property_getAttributes() 런타임 기능을 사용하여 객체의 속성 속성을 가져 오려고합니다. 일부 속성은 읽기 전용으로 설정됩니다. 그러나 문제는 retain/strong, weak 및 assign 속성 간의 차이를 만들려고 할 때입니다. 예 :property_getAttributes()는 읽기 전용으로 설정된 경우 retain, strong, weak 및 assign 속성간에 차이를 만들지 않습니다.
의 우리가 있다고 가정 해 봅시다 :
@interface MyObject : NSObject
@property (assign, readonly) NSObject *prop1;
@property (strong, readonly) NSObject *prop2;
@property (weak, readonly) NSObject *prop3;
@end
우리는 속성 목록 및 인쇄를 얻을 수
int outCount;
objc_property_t *properties = class_copyPropertyList([MyObject class], &outCount);
for(i = 0; i < outCount; i++) {
objc_property_t property = properties[i];
const char *c_attributes = property_getAttributes(property);
printf("%s", c_attributes);
}
free(properties);
결과가 없습니다 :
[email protected]"NSObject",R,V_prop1
[email protected]"NSObject",R,V_prop2
[email protected]"NSObject",R,V_prop3
... 그래서 특정 코드 weak, strong/retain, 읽기 전용 일 때 속성 할당 :(
질문은입니다 : 속성이 약하고 강하다는 것을 아는 다른 방법이 있습니까?
호기심입니다. 왜 이러는거야? – elimirks