美文网首页
objc_getAssociatedObject

objc_getAssociatedObject

作者: 石玉龙 | 来源:发表于2017-01-15 22:53 被阅读25次

id objc_getAssociatedObject(id object, const void *key);

Returns the value associated with a given object for a given key.

Parameters

object

The source object for the association.

key

The key for the association.

Returns

The value associated with the key key for object.

Availability iOS (3.1 and later), macOS (10.6 and later), tvOS (9.0 and later), watchOS (1.0 and later)

objc_setAssociatedObject需要四个参数:源对象,关键字,关联的对象和一个关联策略。

- (UINavigationController *)filterNavigation {

return objc_getAssociatedObject(_sponsor, _cmd);

}

- (void)setFilterNavigation:(UINavigationController *)filterNavigation {

//让sponsor持有filterNavigation

objc_setAssociatedObject(_sponsor, @selector(filterNavigation), filterNavigation, OBJC_ASSOCIATION_RETAIN_NONATOMIC);

}

相关文章

网友评论

      本文标题:objc_getAssociatedObject

      本文链接:https://www.haomeiwen.com/subject/lwsubttx.html