Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 对于NSMutableArray的Objective-C中的每个循环_Php_Ios_Foreach_Nsmutablearray_Nsarray - Fatal编程技术网

Php 对于NSMutableArray的Objective-C中的每个循环

Php 对于NSMutableArray的Objective-C中的每个循环,php,ios,foreach,nsmutablearray,nsarray,Php,Ios,Foreach,Nsmutablearray,Nsarray,或 我可以设置关键点和值。现在,我只想访问每个键和值,但我不知道设置了多少个键 在PHP中非常简单,如下所示: NSArray *output = [[NSMutableArray alloc]init]; 在Objective-C中如何实现这一点?用于管理键和值的用法用于管理NSArray的键和值的用法: foreach ($output as $key => $value) 对于NSD字典: for (id item in output) { // go nuts } [

我可以设置关键点和值。现在,我只想访问每个键和值,但我不知道设置了多少个键

在PHP中非常简单,如下所示:

NSArray *output = [[NSMutableArray alloc]init];
在Objective-C中如何实现这一点?

用于管理键和值的用法

用于管理NSArray的键和值的用法

foreach ($output as $key => $value)
对于NSD字典:

for (id item in output) {
    // go nuts
}
[output objectAtIndex:1];  // 1 is the index number
我使用泛型id类型,因为我不知道您使用的键和值的类型。如果您知道特定的类名,则应使用它们。

对于NSArray:

foreach ($output as $key => $value)
对于NSD字典:

for (id item in output) {
    // go nuts
}
[output objectAtIndex:1];  // 1 is the index number

我使用泛型id类型,因为我不知道您使用的键和值的类型。如果你知道特定的类名,你应该使用它们。

我认为你把NSDictionary和NSArray混淆了

在NSDictionary中,可以使用如下键设置对象

for (id key in output) {
    id value = [output objectForKey:key];
    // go nuts
}
你可以得到这样的物体

NSMutableDictionary *output = [[NSMutableDictionary alloc]init]; 
[yourDictionary setObject:@"yourvalue" forKey:@"yourKey"];
在数组中,它只是将对象添加到索引中

[yourDictionary objectForKey:@"yourKey"];
将对象作为

NSArray * output = [[NSArray alloc] initWithObjects:@"option1",@"option2", nil];

我想你把NSDictionary和NSArray搞混了

在NSDictionary中,可以使用如下键设置对象

for (id key in output) {
    id value = [output objectForKey:key];
    // go nuts
}
你可以得到这样的物体

NSMutableDictionary *output = [[NSMutableDictionary alloc]init]; 
[yourDictionary setObject:@"yourvalue" forKey:@"yourKey"];
在数组中,它只是将对象添加到索引中

[yourDictionary objectForKey:@"yourKey"];
将对象作为

NSArray * output = [[NSArray alloc] initWithObjects:@"option1",@"option2", nil];

在您的示例中,使用第二个数组作为值对象,并使用NSDictionary:

for (id item in output) {
    // go nuts
}
[output objectAtIndex:1];  // 1 is the index number

在您的示例中,使用第二个数组作为值对象,并使用NSDictionary:

for (id item in output) {
    // go nuts
}
[output objectAtIndex:1];  // 1 is the index number

答案可能是这样的?我的意思是,它包含了答案,尽管问题不同,答案可能是这样的?我的意思是,它包含了答案,尽管问题不同,对于字典,你应该使用objectForKey,而不是valueForKey。后者用于键值编码。对于字典,您应该使用objectForKey,而不是valueForKey。后者用于键值编码。