This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| I want to use some different templates (say like 5) for every viewController in my App. | |
| There are some different approaches i can think of: | |
| 1-> have 5 different storyboards repeating the same navigation in each of them. Since the app may/would change, im discard this option since i have to redo in 5 storyboards every change i made in the navigation. | |
| 2- Have a storyboard with all the VCs and the relation between them, and for each VC have a containerView, where i instantiate from other Storyboards the viewControllers inside the container. The other storyboards only will have the vcs without navigation, just separate scenes.(The cons here is that i need a VC for the container just setting the content of the container, so for every scene i need 1 containerVC, and another VC that is actually the real code that all the vc share) | |
| 3- Having the same storyboard and creating 5 xibs for each scene in the storyboard, so ill set the file owner to the current vc in the storyboard, and i add a subview like: | |
| view. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 1: | |
| class ViewController: UIViewController { | |
| override func loadView() { | |
| view = NSBundle.mainBundle().loadNibNamed("View", owner: self, options: nil).first! as UIView | |
| } | |
| } | |
| 2: | |
| class ViewController: UIViewController { | |
| override func viewDidLoad() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override func viewDidLayoutSubviews() { | |
| super.viewDidLayoutSubviews() | |
| let vc = storyboard?.instantiateViewControllerWithIdentifier("test") as UIViewController | |
| self.addChildViewController(vc) | |
| self.container.addSubview(vc.view) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override func viewWillLayoutSubviews() { | |
| super.viewWillLayoutSubviews() | |
| let vc = storyboard?.instantiateViewControllerWithIdentifier("test") as UIViewController | |
| self.container.addSubview(vc.view) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| let vc = storyboard?.instantiateViewControllerWithIdentifier("test") as UIViewController | |
| self.container.addSubview(vc.view) | |
| updateGUI() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TestVC: UIViewController { | |
| @IBOutlet weak var container: UIView! // Outlet to container on IB | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| let vcToAdd = storyboard?.instantiateViewControllerWithIdentifier("vcToAdd") as UIViewController | |
| self.container = vcToAdd.view | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //OUTPUT sharedInstance | |
| public class func go() { | |
| let single = Singleton(name: "Testing") | |
| println(Singleton.sharedInstance.name) | |
| } | |
| public class Singleton { | |
| public class var sharedInstance: Singleton { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Singleton { | |
| class var sharedInstance: Singleton { | |
| var name: String? | |
| struct Static { | |
| static var instance: Singleton? | |
| static var token: dispatch_once_t = 0 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var myObject: CustomObject? { | |
| didSet { | |
| println(newValue.id) //i expect anything like this | |
| //but i end doing like this since newValue doesnt exists inside didSet | |
| println(myObject!.id) //forcing unwrapping | |
| } | |
| } | |
| class CustomObject { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TutorialViewController: UIPageViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate { | |
| var images: [String]! | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| images = ["0","1","2"] | |
| self.delegate = self | |
| self.dataSource = self | |
| let startingViewController: PageContentViewController! = viewControllerAtIndex(0) |