New project files requiring the import of UIKit(需要导入 UIKit 的新项目文件)
问题描述
我有一个项目 A,我开始使用 Swift1-Xcode6 编写它.我有一些扩展文件,例如:
I have a project A, which I started writing with Swift1-Xcode6. I have some extension files like:
extension UIView {
convenience init(x: CGFloat, y: CGFloat, w: CGFloat, h: CGFloat) {
self.init(frame: CGRect(x: x, y: y, width: w, height: h))
}
}
我创建了一个新项目 B 并将这些扩展文件复制到其中.我收到此错误:
I created a new project B and copied these extension files in there. I am getting this error:
UIViewExtensions.swift:11:11: Use of undeclared type 'UIView'
Project-A 中的文件不需要包含 UIKit,但 Project-B 需要.是什么原因?
Files in Project-A do not need the inclusion of UIKit, but Project-B does. What is the reason?
推荐答案
这可能是因为您在桥接头中导入了一些 Objective-C 框架,而这些框架恰好在其 .h 文件中导入了 UIKit - 它会自动将 UIKit 导入到您的所有Swift 类
This probably happens because you import some Objective-C Frameworks in your bridging header that happens to import UIKit in its .h file - which automatically imports UIKit to all your Swift classes
这篇关于需要导入 UIKit 的新项目文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:需要导入 UIKit 的新项目文件
基础教程推荐
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
