Xcode auto-complete source order dependent

I'm unsure if this is a bug in Swift/Xcode (I can reproduce in 12.4 and 12.5) or just a weird quirk that I've somehow managed to avoid running into but is it expected that the ability for Xcode to offer auto-complete suggestions is dependent on the order of how things are defined within a source code file? I know that Playgrounds are parsed from top to bottom but I didn't think this was the case for normal source files in a project.

Here's a basic example - in this example no auto-complete suggestions will be offered on the returned AnyPublisher - you'd expect the normal operators offered on any Combine publisher:

import Combine
import Foundation

let wrapper = Wrapper(createPublisher: { Just("foo").eraseToAnyPublisher() })

// This will not produce any auto-complete suggestions
wrapper.createPublisher().

struct Wrapper {
    var createPublisher: () -> AnyPublisher<String, Never>
}

However if Wrapper is moved above where it is used, auto-complete works as expected:

import Combine
import Foundation

struct Wrapper {
    var createPublisher: () -> AnyPublisher<String, Never>
}

let wrapper = Wrapper(createPublisher: { Just("foo").eraseToAnyPublisher() })

// This *will* provide auto-complete suggestions
wrapper.createPublisher().

It feels like if this was normal I'd have run into it before now.

Is nobody else experiencing this? Auto-complete in Xcode seems to be horribly broken at the moment. I'm experiencing lots of issues with struct properties not auto-completing. Here's another example, using The Composable Architecture.

If I have a simple reducer, my environment properties autocomplete:

let reducer = Reducer<State, Action, Environment> { state, action, environment in
  return environment. // autocomplete here works
}

If I have a combined reducer with just a single reducer it works:

let reducer = Reducer<State, Action, Environment>.combine(
  .init { state, action, environment in
    return environment. // autocomplete here works
  }
)

If I have some other inline above it in the combined list, it works:

let reducer = Reducer<State, Action, Environment>.combine(
  .init { state, action, environment in
    return environment. // autocomplete here works
  },

  .init { state, action, environment in
    return environment. // autocomplete here works
  }
)

But I have some other child reducer stored in a variable somewhere above it in the combined list, it does not work:

let reducer = Reducer<State, Action, Environment>.combine(
  childReducer.pullback(...),

  .init { state, action, environment in
    return environment. // autocomplete here DOES NOT work
  }
)

It's not that no one is experiencing this, it's that we all experience it so often that we no longer find it noteworthy. Xcode's autocomplete breaks on a regular basis, just like its syntax highlighting, so it's just become a fact of life for Swift developers. If you have specific examples that reproduce issues, or just general problems, you can report them to bugs.swift.org and Apple's Feedback system.

1 Like

Yep, that's absolutely the problem . Hope Apple could fix it completely in next major release.

Furthermore, OS X era had been over, maybe it's time to rebuild X code IDE from ground up using swift[UI] and rebrand it as Swift Code swiftly. :wink:

This is the sad answer to your question.

I did file this bug with Apple a while back. You should too. It might even help.