Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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
Ios 在nsmutablearray的内部数组中编辑值_Ios_Objective C_Cocoa Touch - Fatal编程技术网

Ios 在nsmutablearray的内部数组中编辑值

Ios 在nsmutablearray的内部数组中编辑值,ios,objective-c,cocoa-touch,Ios,Objective C,Cocoa Touch,因此,我有以下NSmutableArray: Printing description of globals->_info: <__NSCFArray 0x8a979c0>( { rep = "name"; PriceA = 150; PriceB = 150; nextInvoice = 1001000001; }, { rep = "othername"; PriceA = 150; PriceB = 150;

因此,我有以下NSmutableArray:

Printing description of globals->_info:
<__NSCFArray 0x8a979c0>(
{
    rep = "name";
    PriceA = 150;
    PriceB = 150;
    nextInvoice = 1001000001;
},
{
    rep = "othername";
    PriceA = 150;
    PriceB = 150;
    nextInvoice = 1001000001;
}
)
globals的打印说明->\u信息:
(
{
rep=“name”;
价格a=150;
价格b=150;
nextInvoice=1001000001;
},
{
rep=“othername”;
价格a=150;
价格b=150;
nextInvoice=1001000001;
}
)
如何在下一个语音中增加一个


谢谢

您的内部对象也是词典

您可以改为使用NSMutableDictionary

但是我认为是时候创建一个自己的类并使用数组中的实例了。

这是一个(不可变)数组,它包含两个字典类型的对象。假设字典是可变的,那么选择:

(假设它被命名为outerArray)

根据您来自何处,此样式可能更易于阅读: (希望我没弄错,不要经常使用;如果有人发现错误,请随意编辑)


但是请注意,只有当外部数组中的内部字典实际上是可变的时,这才有效

那么,对于哪些内部数组,您希望将nextInvoice int增加1?顺便说一下,它们需要是可变的。还有,那些内部的“数组”看起来很像字典……你怎么判断数组中的内容是数组的?我刚才想,它们是不是字典?谢谢,它可以工作。您在MutableDictionary上有一个输入错误,并且没有关闭下一张发票的“之后”“但是谢谢汉克斯。修正了答案。仍然是一个拼写错误,而不是字典:)如果可以用简单的方式完成,为什么要新建一个类?你的ans不会做任何修改sense@hussainShabbir,让我猜猜:您通常懒得创建自定义类?类是创建模型对象的完美方式。您的评论毫无意义。编辑数组时不需要创建自定义类。所以请你最好删除你的ans
NSMutableDictionary *innerDict = [outerArray objectAtIndex:0];
NSNumber *aNumber  = [innerDict objectForKey:@"nextInvoice"];
NSNumber *bNumber  = [NSNumber numberWithInt: [aNumber intValue] +1];
[innerDict setObject:bNumber forKey:@"nextInvoice"];
NSMutableDictionary *innerDict = outerArray [0];
NSNumber *aNumber  = innerDict [@"nextInvoice"];
NSNumber *bNumber  = @(aNumber intValue] +1);
innerDict[@"nextInvoice"] = bNumber;