这是一个非常奇怪的错误
当您尝试将枚举传递给初始化程序的参数时会发生这种情况,自动完成将失败,并且在键入 Enum. 后不会提示枚举案例,它会列出您正在调用初始化程序的类的实例成员在。如果您尝试使用单点语法 (.Case),自动完成功能也会失败,但不会显示实例成员列表,而是不会显示任何内容。
我最初认为这可能与您的枚举和类的命名有关(BuildingType & Building),但事实并非如此。
这个错误似乎只出现在具有多个参数(其中一个是枚举)的初始化程序中。我无法使用单参数初始化程序重现此问题。
重现性似乎取决于初始化程序是否“完整”。如果初始化器定义了所有参数名称和值(枚举除外),我正在考虑它是“完整的”。例如:
// Incomplete (foo is one argument of many)
let baz = Baz(foo: Foo.
// Semi-Complete (before you assign the second parameter a value)
let baz = Baz(foo: Foo., string: <String Placeholder>)
// Complete
let baz = Baz(foo: Foo., string: "")
// Complete (note the lack of the last bracket)
let baz = Baz(param: 0, foo: Foo.
这是我的测试设置(Xcode 7.3、Swift 2.2):
enum Foo {
case Bar
}
class Baz {
var iReallyShouldntBeDisplayedHere = 0
init(foo:Foo, string:String) {}
init(foo: Foo) {}
}
以下是我发现错误发生和未发生的情况列表:
// Enum is the only argument
// CORRECT: accepting the initialiser's autocomplete (so it's 'complete'), then typing "Foo." brings up autocomplete options for enum cases
let baz = Baz(foo: Foo.)
// CORRECT: typing the initialiser yourself (so it's 'incomplete'), then typing "Foo." in the first parameter brings up autocomplete options for enum cases
let baz2 = Baz(foo: Foo.
// Enum is one argument of many
// INCORRECT: accepting the initialiser's autocomplete (so it's 'semi-complete'), then typing "Foo." in the first parameter brings up Baz's instance members ("iReallyShouldntBeDisplayedHere")
let baz3 = Baz(foo: Foo., string: <String Placeholder>)
// CORRECT: typing the initialiser yourself (so it's 'incomplete'), and typing "Foo." in the first parameter brings up enum cases
let baz4 = Baz(foo: Foo.
// Single dot syntax (where enum is one argument of many)
// CORRECT: typing the initialiser yourself (so it's 'incomplete'), and typing "." in the first parameter brings up enum cases
let baz5 = Baz(foo:.
// CORRECT: accepting the initialiser's autocomplete (so it's 'semi-complete'), then typing "." in the first parameter brings up enum cases
let baz6 = Baz(foo:., string: <String Placeholder>)
// INCORRECT: modifying the foo: argument once the initialiser is 'complete' by typing "." in the first parameter doesn't generate the autocomplete list
let baz7 = Baz(foo:., string: "")
我也尝试过 foo: 是最后一个参数,但在这种情况下初始化程序总是必须是完整的,所以它总是失败。我确实尝试使用带有 3 个参数的初始化器,但它似乎与带有 2 个参数的初始化器具有相同的行为。
如果有人知道更多可以重现此错误的情况,我很想知道!