演讲者 1.0.0

演讲者 1.0.0

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最新发布2016年10月
SPM支持SPM

muukiimuukii 维护。



演讲者 1.0.0

演讲者

使用安全和干净的代码进行屏幕转换。

使用演讲者,您可以……

  • 确保ViewController满足要求,例如注入ViewModel。
  • 约束转换类型(推送、展示模态或两者都可以)

此库建议与即时可实例化一起使用。

用法

干净的屏幕转换

MyViewController.Presenter(userID: "muukii").push(self.navigationController)
MyViewController.Presenter(userID: "muukii").present(self)

高级

MyViewController.Presenter(userID: "muukii").push(self.navigationController) { (transaction: PushTransaction<MyViewController> in

    // Pop    
    transaction.pop()

    // Get
    transaction.viewController
}

MyViewController.Presenter(userID: "muukii").present(self) { (transaction: ModalTransaction<MyViewController>) in

    // Pop    
    transaction.dismiss()

    // Get
    transaction.viewController
}

创建演讲者

推送

extension MyViewController {

    final class Presenter: PushPresenter {

        let userID: String

        init(userID: String) {
            self.userID = userID
        }

        func createViewController() -> MyViewController {
            let controller = MessagesViewController() // Init from Stroyboard or XIB
            controller.userID = userID
            return controller
        }  

        // Optional:

        public func willPush(viewController: MyViewController) {

        }

        public func didPush(viewController: MyViewController) {

        }
    }
}

展示

extension MyViewController {

    final class Presenter: ModalPresenter {

        let userID: String

        init(userID: String) {
            self.userID = userID
        }

        func parentController(viewController: UIViewController) -> UIViewController? {
            return UINavigationController(rootViewController: viewController)
        }

        func createViewController() -> MyViewController {
            let controller = MessagesViewController() // Init from Stroyboard or XIB
            controller.userID = userID
            return controller
        }   

        // Optional

        public func willPresent(viewController: MyViewController) {

        }

        public func didPresent(viewController: MyViewController) {

        }
    }
}

展示或推送

extension MyViewController {

    final class Presenter: PushPresenter, ModalPresenter {

        let userID: String

        init(userID: String) {
            self.userID = userID
        }

        func parentController(viewController: UIViewController) -> UIViewController? {
            // Call Present() only
            return UINavigationController(rootViewController: viewController)
        }

        func createViewController() -> MyViewController {
            let controller = MessagesViewController() // Init from Stroyboard or XIB
            controller.userID = userID
            return controller
        }    

        // Optional

        public func willPresent(viewController: MyViewController) {

        }

        public func didPresent(viewController: MyViewController) {

        }

        public func willPush(viewController: MyViewController) {

        }

        public func didPush(viewController: MyViewController) {

        }
    }
}

要求

安装

演讲者通过CocoaPods提供。要安装它,只需将以下行添加到您的Podfile中

pod "Presenter"

作者

muukii,[email protected]

许可证

演讲者在MIT许可下提供。有关更多信息,请参阅LICENSE文件。