开发者

What is error in this code?

开发者 https://www.devze.com 2023-03-30 15:38 出处:网络
for(NSDictionary *feed in Feeds) { NSString *feedName=[feed objectForKey:@\"name\"]; if(listofBusiness==nil)
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
         }
0

精彩评论

暂无评论...
验证码 换一张
取 消