Often this indicates that your code doesn't currently compile. Swift often has trouble computing types on code that itself isn't correct. In some cases it's a bug in the compiler. Use of AnyObject
can be particularly confusing to the compiler, and should be avoided as much as possible. In this case, AnyObject
is required, but you should try to get it converted to a specific type quickly. Don't return [AnyType]
for instance if you can possibly help it.
But the short answer is that the Swift compiler is still evolving, and it can't always work out types in complex situations, particularly on partial or (currently) incorrect code.
Note that you're using var
for a lot of things that should be let
. Unless you actually need to modify the variable, you should prefer let
. It helps you prevent many kinds of bugs, and can be easier on the compiler to deal with (since the variable has fewer ways it can change).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…