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))
}
}
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'
Files in Project-A do not need the inclusion of UIKit, but Project-B does. What is the reason?
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
UIView
is defined in the UIKit framework, so a Swift file using
that class needs to import UIKit
.
But since all Swift files import the (Swift mapping of the)
bridging header file, it would also be sufficient if the bridging header file directly or indirectly imports the UIKit framework.
That could be the reason why you did not have to import it explicitly
in the Swift file in your older project.