我想将数字存储在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