Skip to content

Instantly share code, notes, and snippets.

@fmo91
Created January 4, 2017 04:29
Show Gist options
  • Save fmo91/f6b60d70bd82443ffba72641e8df2d7c to your computer and use it in GitHub Desktop.
Save fmo91/f6b60d70bd82443ffba72641e8df2d7c to your computer and use it in GitHub Desktop.
Sample view controller that is instantiated using xibs.
//
// SampleViewController.swift
// MediumSamples
//
// Created by Fernando Ortiz on 1/4/17.
// Copyright © 2017 Fernando Martín Ortiz. All rights reserved.
//
import UIKit
class SampleViewController: UIViewController {
// This Very important attribute is necessary for this view controller
// to perform some actions.
//
// Note that, in this case, this attribute is declared as 'let',
// it's IMMUTABLE.
let veryImportantAttribute: String
override func viewDidLoad() {
super.viewDidLoad()
}
// In this custom initializer we can send dependencies that are needed
// from this view controller to work properly.
// We simply can't forget to pass data. In that case, the project won't compile.
init(veryImportantAttribute: String) {
self.veryImportantAttribute = veryImportantAttribute
super.init(nibName: "SampleViewController", bundle: nil)
}
// This will be never called, so we don't need to care
// about its implementation.
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment