ios - 如何以递增顺序在数组中追加字符串

标签 ios objective-c nsmutablearray

我有一些 api 调用,它返回一些值并将其存储到数组中,同时接收我可能会从服务器获取重复的值,我想当它已经在数组中并插入新值时不要追加,

这里是我的示例代码:

-(void)getIdValue:(NSString*)getIdVal {

getTagIdList = [[NSMutableArray alloc]init];

BOOL isTheObjectThere = [getTagIdList containsObject: getIdVal];

NSLog(isTheObjectThere ? @"Yes" : @"No");

if (isTheObjectThere == NO){
    [getTagIdList addObject:getIdVal];
    NSLog(@"getTagIdList -->%@",getTagIdList);

} if (isTheObjectThere == YES){
    return;
}

}

我希望所有新数据都应该存储在 getTagIdList 中,但我只得到一条记录正在存储

最佳答案

您在错误的方法中初始化数组。您不应该在尝试存储数据的地方启动数组。(这将删除以前调用中存储的所有旧数据)

关于ios - 如何以递增顺序在数组中追加字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44179767/

相关文章:

objective-c - 相同的函数,都被执行,一个声音都没有

objective-c - b/w addObject :dictionary and addObject:[dictionary copy] to an NSMutableArray? 有什么区别

iphone - 将 NSMutablearray 复制到另一个

objective-c - NSMutableArray 为 null

ios - 如何在谷歌地图 URL 中指定到达日期和时间?

ios - Swift:TableviewController 中的三个原型(prototype)单元格将无法查看

ios - 无法将 UIButton 向下转换为子类

ios - iOS Check ViewController是否具有ChildViewController?

ios - 应用程序在 UIPopoverPresentationController 中崩溃但没有显式弹出窗口?

ios - 如何在 Xcode 中获取表格主题的详细信息?