@@ -62,9 +62,24 @@ - (instancetype)initWithClass:(Class)kls name:(NSString *)propertyName
62
62
_ivar = class_getInstanceVariable (kls, [safeStringWithPropertyAttributeValue (objcProperty, " V" ) UTF8String ]);
63
63
if (_ivar) break ;
64
64
65
- // If we implement a property in a subclass with a different type then the parent, but rely upon the parent's
66
- // implementation, we will have to attempt to infer the variable name...
67
- // TODO: (richardross): Walk the superclass tree for the synthesized value?
65
+ // Walk the superclass heirarchy for the property definition. Because property attributes are not inherited
66
+ // (but property definitions *are*), we must be careful to ensure that the variable was never actually
67
+ // implemented and synthesized in a superclass. Note if the same property is synthesized in multiple classes
68
+ // with different iVars, we take the class furthest from the root class as the 'source of truth'.
69
+ Class superClass = class_getSuperclass (kls);
70
+ while (superClass) {
71
+ objc_property_t superProperty = class_getProperty (superClass, [_name UTF8String ]);
72
+ if (!superProperty) break ;
73
+
74
+ _ivar = class_getInstanceVariable (superClass, [safeStringWithPropertyAttributeValue (superProperty, " V" ) UTF8String ]);
75
+ if (_ivar) break ;
76
+
77
+ superClass = class_getSuperclass (kls);
78
+ }
79
+
80
+ if (_ivar) break ;
81
+
82
+ // Attempt to infer the variable name.
68
83
_ivar = class_getInstanceVariable (kls, [[@" _" stringByAppendingString: _name] UTF8String ]);
69
84
if (_ivar) break ;
70
85
@@ -86,11 +101,19 @@ - (instancetype)initWithClass:(Class)kls name:(NSString *)propertyName
86
101
_setterSelector = NSSelectorFromString (propertySetter);
87
102
88
103
if (_associationType == PFPropertyInfoAssociationTypeDefault) {
89
- // TODO: (richardross) Check if the property is weak as well.
90
104
BOOL isCopy = safeStringWithPropertyAttributeValue (objcProperty, " C" ) != nil ;
91
- _associationType = (_object ? (isCopy ? PFPropertyInfoAssociationTypeCopy
92
- : PFPropertyInfoAssociationTypeStrong)
93
- : PFPropertyInfoAssociationTypeAssign);
105
+ BOOL isWeak = safeStringWithPropertyAttributeValue (objcProperty, " W" ) != nil ;
106
+ BOOL isRetain = safeStringWithPropertyAttributeValue (objcProperty, " &" ) != nil ;
107
+
108
+ if (isWeak) {
109
+ _associationType = PFPropertyInfoAssociationTypeWeak;
110
+ } else if (isCopy) {
111
+ _associationType = PFPropertyInfoAssociationTypeCopy;
112
+ } else if (isRetain) {
113
+ _associationType = PFPropertyInfoAssociationTypeStrong;
114
+ } else {
115
+ _associationType = PFPropertyInfoAssociationTypeAssign;
116
+ }
94
117
}
95
118
96
119
return self;
0 commit comments