Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

  • Unknown type name 'import'
  • Expected ';' after top level declarator

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.

like image 533
vilone Avatar asked Mar 30 '15 11:03

vilone


1 Answers

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.

like image 187
zvonicek Avatar answered Oct 21 '22 20:10

zvonicek