How to Add NSTimeInterval to NSMutableArray?

Discussion in 'iOS Programming' started by Stunner, Nov 11, 2009.

  1. macrumors newbie

    Sep 14, 2009
    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!
  2. Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    Convert it to an object using NSNumber.
  3. thread starter macrumors newbie

    Sep 14, 2009
    Awesome, thanks man. Figured it out.

Share This Page