Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ios newly created swift file import cocoa defaultly in xcode

Tags:

xcode

ios

swift

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

like image 390
dopcn Avatar asked Apr 13 '15 08:04

dopcn


People also ask

How do I import a bridging header in Swift?

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.

What is Cocoa class in Xcode?

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.

How do I import a Swift file into an Objective-C project?

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 .

How do I add Objective-C to Xcode?

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'.


1 Answers

Ensure that you choose your file from iOS section not OS X and then it will use UIKit instead Cocoa

screenshot

like image 122
Azat Avatar answered Sep 17 '22 18:09

Azat