开发者

removing items from NSmutableArray

I have two nsmutablearrays

array1: searchedStores = [[NSMutableArray alloc] init];

array2: allStores; ///it holds Stores information and it is also NSMutableArray

Now if i add objects in "searchedStores" Array

for (int i= 0; i < [allstores count]; i++){开发者_JS百科
  Franchise *store = [allStores objectAtIndex:i];
    if ([store.ZipCode hasPrefix:str])  /// where str is searched string
    {
      [searchedStores addObject:store];    // some stores information will be inserted in "searchedStores" array
    }
}

Now if i remove objects from searchedStores array it will also remove objects from "allStores" array

to remove objects i am writing

[searchedStores removeAllObjects];

How can i remove objects only from "searchedStores" array. and "allStores" Array should keep its objects.


IF you are just assigning allstores array with searchedstores array then changes made in searched stores array will be reflected to allstores. You need to allocate new memory to allstores and then add objects from searchedstores array to it upon your logical behavior.


Every array is totally independent. If removing objects from one array effects the other, you don't have two arrays, but only two pointers to the same array. You need to instantiate (alloc/init or mutableCopy) both. Feel free to show your initialization code as well.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜