Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<<error type>> Strange Error

Tags:

swift

xcode6

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

like image 710
Abdou023 Avatar asked Sep 21 '14 14:09

Abdou023


4 Answers

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.

like image 117
Emin İnanç Ünlü Avatar answered Nov 17 '22 06:11

Emin İnanç Ünlü


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

like image 23
Rob Napier Avatar answered Nov 17 '22 06:11

Rob Napier


<<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?

like image 7
Tim Bodeit Avatar answered Nov 17 '22 06:11

Tim Bodeit


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
like image 6
Abdou023 Avatar answered Nov 17 '22 04:11

Abdou023