我想將數字存儲在NSMutableArray中,但是當我檢查它時,我得到的只是垃圾。存儲在NSMutableArray中的NSNumbers
-(void)storeIntoArray:(int)indexInt
{
NSNumber *indexNum = [[NSNumber alloc] initWithInt:indexInt];
[last100 insertObject:indexNum atIndex:prevCount];
prevCount++;
if(prevCount > 100)
{
prevCount = 0;
cycledOnce = YES;
}
}
-(BOOL)checkArray:(int)indexInt
{
for(int i = 0;i < [last100 count];i++)
{
NSLog(@"Stored: %d",[last100 objectAtIndex:i]);
if (indexInt == (int)[last100 objectAtIndex:i]) {
NSLog(@"Same entry, trying again");
return YES;
}
}
return NO;
}
當我檢查,我會回來的值一樣Stored: 110577680
,只是不同的垃圾值。
不是這是你的問題,而是你泄漏你存儲的每一個數字。 – 2012-01-16 04:26:12
好的。發佈indexNum? – Chris 2012-01-16 04:27:17
請注意,使用NSMutableSet來檢測重複條目(如果這是您的意圖)可能會更有效。 – 2012-01-16 04:36:58