Abdou023 Abdou023 - 1 year ago 61
Swift Question

<<error type>> Strange Error

I have encountered a situation where xcode stops auto-completing and if you try to write a variable that already been defined xcode says

<< error type>>

Here is my error:

enter image description here

Answer Source

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).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download