I've been trying to store an NSDate object into an NSMutableArray and then retrieve it later (to get an elapsed time).
Here is what I tried, for mutable array initialization and storage:
in the .h file:
@property (nonatomic, strong) NSMutableArray *startTime;
in the implementation (.m) file:
@synthesize startTime = _startTime;
// init the mutable array - create some temporary elements as placeholders
NSDate *temp = [NSDate date];
for (int i = 0; i < 3; i++) {
[self.startTime addObject:temp];
}
Here's what's not working:
[self.startTime replaceObjectAtIndex:iurl withObject:[NSDate date]]; //iurl is an NSUInteger
NSDate *now = [self.startTime objectAtIndex:iurl];
NSLog(@"Now = %@", now);
All I wanted to do was a) store an NSDate object at an index (NSUInteger iurl here), and then b) retrieve and access that object. In the code above, now is always (null). How can I store an NSDate object into an array or mutable array so it may be retrieved later?
iurlto replace. You can deal with this by adding null objects ([NSNull null]) to pad it out, but if you have to do this I'd have to question why you're using an array to begin with.-arrayWithCapacity:returns an autoreleased object. Are you retaining it anywhere? Because if not, it's probably getting destroyed.