Strange Xcode and autocomplete issue

Strange Xcode and autocomplete issue

A few days ago I experienced a strange issue with the Xcode and its autocomplete functionality that ate some 2-3 hours of my time tracing back when and what happened in the commit history...

Background

I have a big array in a separate file containing items representing all of the countries. Each country item is a tuple of two pairs - code and name:

let countries = [
  (code: "AD", name: "Andorra"),
  (code: "AE", name: "United Arab Emirates"),
  (code: "AF", name: "Afghanistan"),
  ...
  (code: "ZA", name: "South Africa"),
  (code: "ZM", name: "Zambia"),
  (code: "ZW", name: "Zimbabwe")
]

When I build the project, the autocomplete functionality stops working.

Problem

As I mentioned, I spent a good 2-3 hours and finally found out that this file and particularly this variable was causing the strange issue.

The problem was that the type of the countries variable's content was not explicitly declared which is really strange since the code is compiling and the type is inferred.

I'm experiencing this issue in Xcode 11.6 with Swift 5.2.4.

Solution

So the solution was to just explicitly state the array's content type.

let countries: [(code: String, name: String)] = [
  (code: "AD", name: "Andorra"),
  (code: "AE", name: "United Arab Emirates"),
  (code: "AF", name: "Afghanistan"),
  ...
  (code: "ZA", name: "South Africa"),
  (code: "ZM", name: "Zambia"),
  (code: "ZW", name: "Zimbabwe")
]