vilone
vilone

Reputation: 63

Swift: Error when trying to import UIKit

I'm getting this really weird error when trying to import UIKit in my swift file.

My Code is simply:

import UIKit

class Test: NSObject {

}

The error I get at 'import UIKit' is:

I have added UIKit to my Frameworks folder, the class doesn't contain any code (so therefore there shouldn't be anything wrong with it) and I tried to restart both xCode and my Mac, but the error is still there.

I appreciate any help.

Thanks.

EDIT: Solved:

I tried to import 'Test.swift' in AppDelegate.

Upvotes: 6

Views: 9843

Answers (4)

Amal T S
Amal T S

Reputation: 3405

In my case, it was because somehow the selected type in the file inspector was objective-c source instead of Default - Swift Source even though i was using a .swift file.

Changing it to Default - Swift Source solved the issue for me.

enter image description here

Upvotes: 0

Sukhi
Sukhi

Reputation: 14145

The import stuff in swift is case sensitive. Example :

import uikit

will not work. You'll have to type it as

import UIKit

Upvotes: 0

zvonicek
zvonicek

Reputation: 1503

This problem usually happens when you try to import ".swift" file in your Objective-C code, like this: #import "HomeViewController.swift". This is wrong and you should import special, automatically generated Swift header, instead:

#import "ProductModuleName-Swift.h"

where ProductModuleName is the name of your module (or project) containing the Swift code.

Upvotes: 25

Evgeniy S
Evgeniy S

Reputation: 1484

Found good Trouble shooting guide - there is great Troubleshooting Tips and Reminders section!

https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_87

Upvotes: 1

Related Questions