ContainerManager 2.0.1

ContainerManager 2.0.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Dec 2016
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Bruno Rendeiro.



  • By
  • brurend

ContainerManager

Usage

ContainerViewSegueManager

ContainerViewSegueManager is responsible for telling your UIViewController which segue it should perform.

Creating your containerView

After dropping your container into your UIViewController you should name its embedSegue identifier:

Screenshots/EmbedSegueSS.png

you also need to make sure the embed UIViewController custom class is ContainerViewSegueManager

Screenshots/ContainerViewSegueManagerSS.png

and then in your UIViewController class override prepareForSegue:sender: with references to ContainerViewSegueManager and an instance of your ContainerDataManager subclass:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "embedSegue" {
        self.containerView = segue.destinationViewController as! ContainerViewSegueManager

        let data = MyContainerData(fromParent: self, fromContainer: self.containerView)

        self.containerView.containerDataClass = data
    }
}

Make sure shouldPerformSegueWithIdentifier:sender: returns YES

override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
return true
}

EmptySegue

All segues from your ContainerViewSegueManager to your UIViewController should be of the type EmptySegue and have an identifier, don’t forget to set the “Module” to ContainerManager:

Screenshots/EmptySegueSS.png

ContainerDataManager

ContainerDataManager is responsible for deciding which segueIdentifier should be passed to performSegueWithIdentifier:sender: of ContainerViewSegueManager based on your application data and needs.

Subclassing ContainerDataManager

You should create a subclass of ContainerDataManager and override the additionalSetup method:

MyContainerDataManager.h

import UIKit
import ContainerManager

class MyContainerData: ContainerDataManager

Choosing which segueIdentifier will be used

ContainerDataManager additionalSetup method will be overridden by your class implementation. self.currentSegueIdentifier must NOT be nil.

override func additionalSetup() {
    let array = [1,2,3]

    if array.count != 0 {
        self.currentSegueIdentifier = "FirstViewController"
    }

    else {
        self.currentSegueIdentifier = "SecondViewController"
    }
}

Swapping viewController

You can use ContainerViewSegueManager swapFromViewController:toViewController to go from one UIViewController to another UIViewController easily.

let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let second = storyboard.instantiateViewControllerWithIdentifier("SecondViewController")        
container.swapFromViewController(self, toViewController: second)

Requirements

ContainerManager supports iOS 8.3+. Updated to Swift 3.0

Installation

ContainerManager supports multiple methods for installing the library in a project.

Author

Bruno Rendeiro, [email protected].

License

ContainerManager is available under the MIT license. See the License file for more info.