I'm developing an iOS app and want to build new features in swift now. But when I create a new file by Xcode->File->New->File->Cocoa Class->Language Swift the newly created file always import Cocoa
instead of UIKit
.
Is this the default behavior for all of you? And is there a way to change to import UIKit every time create a new swift file?
UPDATE: thanks for all the answers. I made a terrible mistake
Alternatively, you can create a bridging header yourself by choosing File > New > File > [operating system] > Source > Header File. Edit the bridging header to expose your Objective-C code to your Swift code: In your Objective-C bridging header, import every Objective-C header you want to expose to Swift.
Cocoa and Cocoa Touch are the application development environments for OS X and iOS, respectively. Both Cocoa and Cocoa Touch include the Objective-C runtime and two core frameworks: Cocoa, which includes the Foundation and AppKit frameworks, is used for developing applications that run on OS X.
Import Swift code into Objective-C within the same framework: Under Build Settings, in Packaging, make sure the Defines Module setting for that framework target is set to Yes. Import the Swift code from that framework target into any Objective-C .
Add any Objective-C file to your Swift project by choosing File -> New -> New File -> Objective-C File. Upon saving, Xcode will ask if you want to add a bridging header. Choose 'Yes'.
Ensure that you choose your file from iOS
section not OS X
and then it will use UIKit
instead Cocoa
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With