What is error in this code?
for(NSDictionary *feed in Feeds)
{
NSString *feedName=[feed objectForKey:@"name"];
if(listofBusiness==nil)
{
开发者_JAVA技巧listofBusiness=[[NSMutableArray alloc]init];
}
if([listofBusiness indexOfObject:feedName] !=NSNotFound)
{
[listofBusiness addObject:feedName];
[feedName release];
feedName=nil;
}
}
in this code when compiler comes on this statement
if([listofBusiness indexOfObject:feedName] !=NSNotFound)
then not go into codition and go to increment in for loop so that any element is not added in array.what is error in this code?
The logic appears to be inverted - you probably want it to add the elemement when
[listofBusiness indexOfObject:feedName] == NSNotFound
But at the moment you have the opposite - you only try to add the object when it is 'not not found' - i.e. when it is already present in the list.
indexOfObject is not working for an array
Try with containsObject method of an array.
Example :
if([listofBusiness containsObject:feedName]) {
// your code
}
精彩评论