How does the Objective-C runtime treat a property that is defined as weak
in a class, but a private category on the class defines a property of the same name and type as strong
?
Will code running in the context of the Category use the original (weak) modifier, or will it use the category defined modifier (strong)?
For example:
Name.m
@property (weak, nonatomic) NSString *name;
NameTests.m
@interface Name (Test)
@property (strong, nonatomic) NSString *name;
@end
In a property declaration, weak
only applies to the synthesized setter method, if any, and synthesized instance variable, if any. If neither of those are synthesized then weak
has no effect.
If the setter and instance variable are synthesized, the question then is: which property declaration is the compiler using to synthesize the setter and instance variable?
The compiler will never synthesize a property declared in a named category. So in your example, name
is a weak property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With