Swift:尝试导入UIKit时出错 [英] Swift: Error when trying to import UIKit
问题描述
尝试在我的swift文件中导入UIKit时,我遇到了这个非常奇怪的错误。
I'm getting this really weird error when trying to import UIKit in my swift file.
我的代码很简单:
import UIKit
class Test: NSObject {
}
我在'import UIKit'得到的错误是:
The error I get at 'import UIKit' is:
- 未知类型名称'import'
- 在顶级声明者之后预期';'
I已经将UIKit添加到我的Frameworks文件夹中,该类不包含任何代码(因此不应该有任何问题)并且我尝试重新启动xCode和我的Mac,但错误仍然存在。
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.
我感谢您的帮助。
谢谢。
编辑:
解决:
我试图在AppDelegate中导入'Test.swift'。
I tried to import 'Test.swift' in AppDelegate.
推荐答案
当您尝试在Objective-C代码中导入.swift文件时,通常会发生此问题,如下所示: #importHomeViewController.swift
。这是错误的,您应该导入特殊的,自动生成的Swift标头,而不是:
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:
#importProductModuleName-Swift.h
其中 ProductModuleName
是包含Swift代码的模块(或项目)的名称。
where ProductModuleName
is the name of your module (or project) containing the Swift code.
这篇关于Swift:尝试导入UIKit时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!