I want to use NSMutableDictionary to cache some data i will use later. My custom object is following:
@interface MyData : NSObject {
NSRange range;
NSMutableArray *values;
}
@property (nonatomic, retain) NSMutableArray *values;
and implement:
- (id)init {
if (self = [super init]) {
values = [[NSMutableArray alloc] init];
}
return self;
}
and when i wanna cache it, i use it like this:
NSMutableDictionary *cache = [[NSMutableDictionary alloc] init];
NSString *key = @"KEY";
MyData *data = [[MyData alloc] init];
// save some data into data
[data.values addObject:"DATA1"];
[data.values addObject:"DATA2"];
//... ...
[cache setObject:data forKey:key];
My questions is the count of cache.values is zero when i retrieve this object later as follow:
[cache objectForKey:@"KEY"];
i can retrieve "data" and the object's memory address is the same as the address when i put it into cache. what's wrong? i need some kind guys help, any info is helpful. thanks