Create application without storyboard in Swift language – iOS8

We can create a navigation based application in swift language without using storyboards like this

  1. Create an empty application
  2. Create ViewController To be made as root viewcontroller


  3. SwiftStudyViewController.swift

    import UIKit

    class SwiftStudyViewController: UIViewController {

    init(nibName nibNameOrNil: String!, bundle nibBundleOrNil: NSBundle!) {

    super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)

    }

    override func viewDidLoad() {

    super.viewDidLoad()

    }

    }

  4. Changes in App Delegate to push a navigation controller with the view controller as root

  5. import UIKit

    @UIApplicationMain
    class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    var navigationController: UINavigationController?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: NSDictionary?) -> Bool {

    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
    // Override point for customization after application launch.
    self.window!.backgroundColor = UIColor.whiteColor()
    self.window!.makeKeyAndVisible()

    // approach without storyboard
    // Step 1: create view controller instance
    // Step 2: create a navigation controller with view controller instance as root
    // Step 3: navigation controller instance is set as rootviewcontroller of the window
    var studyController: SwiftStudyViewController? = SwiftStudyViewController(nibName: “SwiftStudyViewController”, bundle: nil)
    self.navigationController = UINavigationController(rootViewController: studyController)
    self.window!.rootViewController = self.navigationController

    return true

    }

    ..
    ..
    ..
    ..
    ..
    ..

    ** Note: Extension of swift files are .swift.
    Remember to create the xib file for the respective .swift viewcontroller file.

    Cheers!!

    Advertisements

6 thoughts on “Create application without storyboard in Swift language – iOS8

  1. Pingback: Create application without storyboard in Swift language – iOS8 | Suslov Babu - appgong
  2. I put in your code verbatim, and created the view controller with the same name with a xib file of the same name. This line is giving an error:

    var studyController: SwiftStudyViewController? = SwiftStudyViewController(nibName: “SwiftStudyViewController”, bundle: nil)

    It’s asking me to insert , in “SwiftStudyViewController”. Any thoughts?

    Thanks,
    -Callum.

    Liked by 1 person

  3. Pingback: Branden Snedden

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s