xcode objc_setAssociatedObject 在 iOS 中不可用吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13936429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is objc_setAssociatedObject not available in iOS?
提问by openfrog
I'm trying to add "properties" to categories using associate objects API.
我正在尝试使用关联对象 API 向类别添加“属性”。
objc_setAssociatedObject(self, &kIsAnimatingAssocObjKey, animating,
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
Xcode complains:
Xcode 抱怨:
Implicit declaration of function 'objc_setAssociatedObject' is invalid in C99
函数 'objc_setAssociatedObject' 的隐式声明在 C99 中无效
and
和
Use of undeclared identifier 'OBJC_ASSOCIATION_RETAIN_NONATOMIC'
使用未声明的标识符 'OBJC_ASSOCIATION_RETAIN_NONATOMIC'
Xcode 4.5.2, iOS SDK 6 with deployment target 6. It does not work.
Xcode 4.5.2,iOS SDK 6,部署目标为 6。它不起作用。
None of the articleson obj_assoc mention that I must import anything special.
obj_assoc上的文章都没有提到我必须导入任何特殊的东西。
回答by Till
Simply import the runtime header:
只需导入运行时标头:
#import <objc/runtime.h>
#import <objc/runtime.h>