PDA

View Full Version : How to Add NSTimeInterval to NSMutableArray?




Stunner
Nov 11, 2009, 11:33 PM
I am having problems adding NSTimeInterval to an NSMutableArray. Here is my code:

NSTimeInterval timeDifference;
timeDifference = [[self.arrayOfTimes objectAtIndex:arrayOfTimesCtr-1]
timeIntervalSinceDate:[self.arrayOfTimes objectAtIndex:arrayOfTimesCtr-2]];
[self.arrayOfTimeDifferences addObject:timeDifference]; //problem here


And the error I get from the problematic line is "error: incompatible type for argument 1 of 'addObject:'". So what I get from this is that it wants an object rather than a value, but I have looked through the array documentation and there are only addObject methods. Therefore I am wondering how I can append a regular value, like an int, or an NSTimeInterval for that matter, to an array. Thanks!



dejo
Nov 11, 2009, 11:41 PM
Therefore I am wondering how I can append a regular value, like an int, or an NSTimeInterval for that matter, to an array. Thanks!
Convert it to an object using NSNumber.

Stunner
Nov 12, 2009, 12:31 AM
Convert it to an object using NSNumber.

Awesome, thanks man. Figured it out.