gpt4 book ai didi

Objective-C:在 for 循环中将对象添加到 NSArray

转载 作者:太空狗 更新时间:2023-10-30 03:56:44 25 4
gpt4 key购买 nike

我试图遍历一个数组(比较地址),并找到匹配的字符串(currentAddr)并尝试只将匹配的字符串放入另一个数组,但我不断收到错误

“NSArray 的可见@Interface 声明选择器addObject”

NSArray *matchedAddr;
//NOTE: multiple addresses from compareAddr[i] may match to multiple stored Addresses
for (NSUInteger i = 0; i < [compareAddr count]; i++)
{
//Checking IF the obtained key (Mac Address) at compareAddr[i] matches one of the stored Addresses
NSString *currentAddr = [compareAddr objectAtIndex:i];
BOOL addrExists = ([[dictionaryOfAddresses objectForKey:@"StoredAddr"]objectForKey:currentAddr] != nil);

if (addrExists)
{
NSLog (@"Match found at index %1u", i);
[matchedAddr addObject:currentAddr];
}

else { NSLog(@"No Value matches at index %i \n", i); }
}
NSLog (@"Array of matched addresses for further processing %@", matchedAddr);

最佳答案

将其定义为可变的

NSMutableArray *matchedAddr=[[NSMutableArray alloc]init];

关于Objective-C:在 for 循环中将对象添加到 NSArray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12670965/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com