views:

64

answers:

1

I have an Array {-1,0,1,2,3,4...} I am trying to find whether an element exist in these number or not, code is not working

NSInteger ind = [favArray indexOfObject:[NSNumber numberWithInt:3]];

in ind i am always getting 2147483647

I am filling my array like this

//Loading favArray from favs.plist
    NSString* favPlistPath = [[NSBundle mainBundle] pathForResource:@"favs" ofType:@"plist"];
    NSMutableDictionary* favPlistDict = [[NSMutableDictionary alloc] initWithContentsOfFile:favPlistPath];

    NSString *favString = [favPlistDict objectForKey:@"list"];
    NSArray *favList = [favString componentsSeparatedByString:@","];
    //int n = [[favList objectAtIndex:0] intValue];

    favArray = [[NSMutableArray alloc] initWithCapacity:100];
    if([favList count]>1)
    {
        for(int i=1; i<[favList count]; i++)
        {
            NSNumber *f = [favList objectAtIndex:i];
            [favArray insertObject:f atIndex:(i-1)];
        }
    }
+5  A: 

That's the value of NSNotFound, which means that favArray contains no object that isEqual: to [NSNumber numberWithInt:3]. Check your array.

After second edit:

Your favList array is filled with NSString objects. You should convert the string objects to NSNumber objects before inserting them in favArray:

NSNumber *f = [NSNumber numberWithInt:[[favList objectAtIndex:i] intValue]];
Nikolai Ruhe
check now please
coure06