iOS.将对象添加到valueForKeyPath中的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@"answer"valueForKeyPath NSMutableArray中添加一个或多个对象到我现有的NSMutableArray

您可以设置单个NSMutableDictionary对象键值对的值,如

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

此处索引将指向数组内的特定对象。但请记住,数组中的所有对象都应该是可变字典类型的。如果您使用NSDictionary对象,此操作将崩溃。

最新更新