Skip to content

Instantly share code, notes, and snippets.

@pcperini
Last active March 13, 2016 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pcperini/ea5c6b03aab09d3fcecd to your computer and use it in GitHub Desktop.
Save pcperini/ea5c6b03aab09d3fcecd to your computer and use it in GitHub Desktop.
class ContainedViewController: UIViewController {
weak var dataDelegate: FrameViewControllerDataDelegate?
override func willMoveToParentViewController(parent: UIViewController?) {
super.willMoveToParentViewController(parent)
self.dataDelegate = parent as? FrameViewControllerDataDelegate
}
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.dataDelegate?.reloadData()
}
}
extension ContainedViewController: FrameViewControllerDataType {
var titleText: String? {
return "Hello World"
}
}
class FrameViewController: UIViewController {
@IBOutlet var titleLabel: UILabel!
var dataSource: FrameViewControllerDataType?
override func addChildViewController(childController: UIViewController) {
super.addChildViewController(childController)
self.dataSource = childController as? FrameViewControllerDataType
}
}
protocol FrameViewControllerDataType {
var titleText: String? { get }
var dataDelegate: FrameViewControllerDataDelegate? { get set }
}
protocol FrameViewControllerDataDelegate: class {
func reloadData() -> Void
}
extension FrameViewController: FrameViewControllerDataDelegate {
func reloadData() {
self.titleLabel.text = self.dataSource?.titleText
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment