<<error type>> Strange Error
I have started to see same errors after Xcode 6.1 and iOS 8.1 update. I have found that if you delete ModuleCache file at /Users/username/Library/Developer/Xcode/DerivedData/ModuleCache
path, it fixes the error temporarily. And you don't have to close Xcode or the project while doing that. After deleting the file, just wait for Xcode a little to index the project files again. After that, the problem mostly resolves for some time.
As it doesn't solve the problem permanently, you should avoid writing codes causing this according to other answers till Apple solves this.
<<error type>>
can result from the Swift compiler not finding the header file.
Same module:
Do you have some sort of folder structure that your source code is in? If so, try setting Scan All Source Files for Includes
to YES.
This will make Xcode look through all of those folders when trying to find the Header file.
Embedded Projects, multiple modules etc:
1. Check the Search Paths
Have a look where the file in which your type is defined is stored.
In your Build Settings make sure that this location is included in the Search Paths.
If it is part of the User Header Search Paths, make sure, that Always Search User Paths
is turned on.
2. Check dependencies
Have a look at superclasses etc of your type. Are they included in the Search Path as well?
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).
Found out that the error goes away and autocomplete works again if i initialised the variable like this:
var name: String = "my name"
instead of :
var name = "my name" as String