Ryan Ryan - 5 months ago 21x
Swift Question

Boilerplate Code for Subclassing UIViewController in Swift

With Xcode when you create a new Objective-C file with subclass Uiviewcontroller, you get a new file with all the boilerplate code ready to be edited. When I create a new file in swift, it's completely blank. Is this by design? How do I get the same template/boilerplate code so that I can get started coding quickly?

  1. Instead of creating a "Swift File", choose "Cocoa Touch Class":

    enter image description here

  2. Then choose the appropriate subclass:

    enter image description here

  3. Finally click next and save to your desired location.


You may need to change the import statement from import Cocoa to import UIKit