iOS版。在valueForKeyPath中将对象添加到NSMutableArray

时间:2014-11-03 10:42:45

标签: ios objective-c nsmutablearray

如果我的NSMutableArray看起来像这样:

 self.securityQuestionsMutableArray = [[NSMutableArray alloc] init];

 // This is how I would add an object or objects to a `NSMutableArray`
 //[self.securityQuestionsMutableArray addObject:@""];

 {
    answer = "";
    description = "ID Number";
    displayText = "ID Number";
    fieldName = IDNumber;
    secuityQuestionId = 1;
},
    {
    answer = "";
    description = "Test Question";
    displayText = "Test Question";
    fieldName = "Test Questionr";
    secuityQuestionId = 2;
}

如何在valueForKeyPath中添加一个或多个对象@"回答" valueForKeyPath NSMutableArray 到我现有的NSMutableArray

1 个答案:

答案 0 :(得分:0)

您可以像这样设置单个 NSMutableDictionary 对象键值对的值

  

[[self.securityQuestionsMutableArray objectAtIndex:index] setValue:@" new Value" forKeyPath:@"答案"];

这里 index 将指向数组内的特定对象。但请记住,数组中的所有对象都应该是可变字典类型。如果您使用 NSDictionary 对象,则会崩溃。