I think this is a simple issue but I have somehow leaked object in core data. I have a simple one to one relation in core data.
Person <--------> Address
-name -city
-email -country
The person model was relatively simple with just few attributes. But, I wanted to add the getter in Person class to access the city and country from the person class itself. So, I did something like,
@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
With these getter I have been able to access the city with just simple getters in Person model as;
person.city and person.country
But, I feel this is not the correct way to do it. How do I implement this feature to ensure that the memory is not leaked.
You can not access city or country directly from Person,
you can access like….
and no need of implement the: