Created
September 26, 2014 06:22
-
-
Save adison/0461b6637734f435df07 to your computer and use it in GitHub Desktop.
behavior instance class
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
| /* | |
| http://www.objc.io/issue-13/behaviors.html | |
| behavior instance basic | |
| */ | |
| @interface KZBehavior : UIControl | |
| //! object that this controller life will be bound to | |
| @property(nonatomic, weak) IBOutlet id owner; | |
| @end | |
| @implementation KZBehavior | |
| - (void)setOwner:(id)owner | |
| { | |
| if (_owner != owner) { | |
| [self releaseLifetimeFromObject:_owner]; | |
| _owner = owner; | |
| [self bindLifetimeToObject:_owner]; | |
| } | |
| } | |
| - (void)bindLifetimeToObject:(id)object | |
| { | |
| objc_setAssociatedObject(object, (__bridge void *)self, self, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | |
| } | |
| - (void)releaseLifetimeFromObject:(id)object | |
| { | |
| objc_setAssociatedObject(object, (__bridge void *)self, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC); | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment