Last active
January 26, 2016 18:41
-
-
Save FranDepascuali/a2d0da330a89f51c1735 to your computer and use it in GitHub Desktop.
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
extension ViewModelBindable where Self: AnyObject { | |
public var viewModel: ViewModel? { | |
get { | |
return getAssociatedObject(self, key: &AssociatedKey) | |
} | |
set(newViewModel) { | |
if let viewModel = newViewModel { | |
setAssociatedObject(self, value: viewModel, key: | |
&AssociatedKey, policy: | |
objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) | |
if shouldBindViewModel() { | |
registerBinding(viewModel) | |
} | |
} | |
} | |
} | |
private func registerUnbinding(viewModel: ViewModel) { | |
unbindViewModel(viewModel) | |
} | |
private func registerBinding(viewModel: ViewModel) { | |
bindViewModel(viewModel) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment