Is objc_setAssociatedObject not available in iOS?
Asked Answered
C

1

19

I'm trying to add "properties" to categories using associate objects API.

objc_setAssociatedObject(self, &kIsAnimatingAssocObjKey, animating, 
OBJC_ASSOCIATION_RETAIN_NONATOMIC);

Xcode complains:

Implicit declaration of function 'objc_setAssociatedObject' is invalid in C99

and

Use of undeclared identifier 'OBJC_ASSOCIATION_RETAIN_NONATOMIC'

Xcode 4.5.2, iOS SDK 6 with deployment target 6. It does not work.

None of the articles on obj_assoc mention that I must import anything special.

Cupro answered 18/12, 2012 at 15:41 Comment(0)
M
63

Simply import the runtime header:

#import <objc/runtime.h>

Marrissa answered 18/12, 2012 at 15:43 Comment(2)
You answer was entered 4 seconds earlier, therefore I will delete mine (-:Linettelineup
Thanks! Any idea how we are supposed to learn that? Apple documentation used to say. Now it just says "Objective-C framework"Fluellen

© 2022 - 2024 — McMap. All rights reserved.