나는 이것이 간단한 문제라고 생각하지만 핵심 데이터에 어떻게 든 개체가 유출되었습니다. 핵심 데이터에서 간단한 일대일 관계가 있습니다.임시 관계형 속성 만들기
Person <--------> Address
-name -city
-email -country
사람 모델은 속성이 거의없고 비교적 간단했습니다. 하지만 필자는 Person 클래스에 getter를 추가하여 Person 클래스 자체에서 도시와 국가에 액세스하려고했습니다. 그래서, 나는 같은 사람이 모델의 단순한 게터와 도시에 액세스 할 수 있었다 이러한 게터와 같은,
@interface Person:NSManagedObject
@property(nonatomic, strong) NSString *name;
@property(nonatomic, strong) NSString *email;
@property(nonatomic, strong) Address *address;
-(NSString*)city;
-(NSString*)country;
@end
@implementation Person
-(NSString*)city{
[self willAccessValueForKey:@"address"];
NSString *c = [self valueForKeyPath:@"address.city"];
[self didAccessValueForKey:@"address"];
}
-(NSString*)country{
[self willAccessValueForKey:@"address"];
NSString *c = [self valueForKeyPath:@"address.country"];
[self didAccessValueForKey:@"address"];
}
@end
했다;
person.city and person.country
하지만 올바른 방법이 아닌 것 같습니다. 메모리가 유출되지 않도록이 기능을 어떻게 구현합니까?
당신은 사람이 직접 도시 또는 국가에 액세스 할 수 없습니다
아니요 값에 액세스해야하는 상황이 있습니다. 내가 올바르게 수행하고있는 방식은 값을 가져 오지만이 접근법에는 약간의 누수가 있습니다. – Sandeep