Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding swift file to new view controller in xCode? (easy)

I'm just starting out in xCode 6, and I can't seem to figure out how to add a new swift-file to the new view controllers I add in the interface builder.

Any tips on how to proceed would be appreciated.

like image 367
martin Avatar asked Nov 16 '14 22:11

martin


People also ask

How do I add Swift files to Xcode?

To create a new Swift package, open Xcode and select File > New > Swift Package. Choose a name and select a file location. Select “Create Git repository on my Mac” to put your package under version control. On completion, the Swift package opens in Xcode and looks similar to a standard Xcode project.

How do I add a view controller to my storyboard?

Open Main. storyboard and select the Tab Bar Controller Scene. On the right, select the Attribute inspector. You'll find a checkbox named Is Initial View Controller.

Can you mix SwiftUI and UIKit?

The hosting controller is compatible with UIKit since it is a subclass of UIViewController . The purpose of the UIHostingController is to enclose a SwiftUI view so that it can be integrated into an existing UIKit based project.


1 Answers

  1. Add a new Cocoa Touch class. Choose File->New->File... from the menu. Give this new class a name such as "ViewController2" and set the Subclass of: pop down to UIViewController. The file "ViewController2.swift" will be created.

enter image description here

enter image description here

  1. Click on your new View Controller in Interface Builder. In the Identity Inspector (on the right in Xcode) set the Custom Class for the View Controller to "ViewController2".enter image description here
like image 181
vacawama Avatar answered Sep 28 '22 12:09

vacawama