Property with type SEL in Objective-c

SundayMonday picture SundayMonday · Nov 8, 2011 · Viewed 11.1k times · Source

I'd like to declare a property with type SEL like this:

@property (nonatomic, assign) SEL mySelector;

Is "assign" correct here? Perhaps assign can be omitted?

Answer

Joshua Weinberg picture Joshua Weinberg · Nov 9, 2011

assign is the correct annotation here. You use assign for any primitive types. The alternatives (weak, strong/retain) rely on the property pointing at an object to function. I believe the compiler won't even let you declare the wrong type of property for this. If you really wanted to you could omit the assign as it is the default.