需要导入 UIKit 的新项目文件

2023-05-18移动开发问题
3

本文介绍了需要导入 UIKit 的新项目文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个项目 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 的新项目文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

cocos2D iPhone中的UItextfield文本对齐问题
UItextfield text alignment issue in cocos2D iPhone(cocos2D iPhone中的UItextfield文本对齐问题)...
2024-08-12 移动开发问题
7

CCDirecter 用 UIView/nib 替换场景
CCDirecter replace scene with UIView / nib(CCDirecter 用 UIView/nib 替换场景)...
2024-08-11 移动开发问题
3

为什么在 2D iPhone 游戏中使用 Cocos over UI Kit?
Why use Cocos over UI Kit for a 2D iPhone game?(为什么在 2D iPhone 游戏中使用 Cocos over UI Kit?)...
2024-08-11 移动开发问题
3

无法将文件从捆绑包复制到 iOS 中的文档目录
Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)...
2024-04-15 移动开发问题
4

如何复制“字典"在斯威夫特?
How to copy a quot;Dictionaryquot; in Swift?(如何复制“字典在斯威夫特?)...
2024-04-15 移动开发问题
10

Swift - 迭代结构对象时如何对其进行变异
Swift - How to mutate a struct object when iterating over it(Swift - 迭代结构对象时如何对其进行变异)...
2024-04-15 移动开发问题
7