gpt4 book ai didi

ios - Obj-c - 将 NSDictionary 添加到 NSMutableArray?

转载 作者:行者123 更新时间:2023-11-29 05:59:26 25 4
gpt4 key购买 nike

我正在尝试使用以下代码将包含一系列键的 NSDictionary 添加到现有的 NSMutableArray 中。然而,在运行应用程序时,我在最后一行( [self.filtered addObject:nodeData]; )崩溃,上面写着:“EXC_BAD_ACCESS”,我不确定为什么?

ViewController.h

@property (nonatomic, strong) NSMutableArray *filtered;

ViewController.m

-(void)viewDidLoad {


NSString *targetedUser = [self.messageDataFriends objectForKey:@"uid"];

NSString *universal = @"9506";

NSString *myID = [session user][@"user"][@"uid"];

NSPredicate *p1 = [NSPredicate predicateWithFormat:@"uid ==[cd] %@", targetedUser];

NSPredicate *p2 = [NSPredicate predicateWithFormat:@"targetuser ==[cd] %@", myID];

NSPredicate *p3 = [NSPredicate predicateWithFormat:@"uid ==[cd] %@", myID];

NSPredicate *p4 = [NSPredicate predicateWithFormat:@"targetuser ==[cd] %@", targetedUser];

NSPredicate *p5 = [NSPredicate predicateWithFormat:@"targetuser ==[cd] %@", universal];


NSCompoundPredicate *pIntermediary1 = [NSCompoundPredicate andPredicateWithSubpredicates:@[p1, p2]];

NSCompoundPredicate * pIntermediary2 = [NSCompoundPredicate andPredicateWithSubpredicates:@[p3, p4]];

NSCompoundPredicate * pIntermediary3 = [NSCompoundPredicate andPredicateWithSubpredicates:@[p1, p5]];

NSCompoundPredicate *pFinal = [NSCompoundPredicate orPredicateWithSubpredicates:@[pIntermediary1, pIntermediary2, pIntermediary3]];

_filtered = [self.messages filteredArrayUsingPredicate:pFinal];


}


- (IBAction)sendReply:(id)sender {


NSMutableDictionary *nodeData = [NSMutableDictionary new];

[nodeData setObject:@"messages" forKey:@"type"];


NSDictionary *messageValues = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:sentText, nil] forKeys:[NSArray arrayWithObjects:@"value", nil]];
NSDictionary *finalMessage = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:messageValues] forKey:@"und"];

[nodeData setObject:finalMessage forKey:@"body"];

self.replyField.text = @"";

NSString *targetedUser = [self.messageData objectForKey:@"uid"];


NSDictionary *targetMessage = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:targetedUser, nil] forKeys:[NSArray arrayWithObjects:@"value", nil]];
NSDictionary *finalUser = [NSDictionary dictionaryWithObject:[NSArray arrayWithObject:targetMessage] forKey:@"und"];

[nodeData setObject:finalUser forKey:@"field_targetuser"];


[nodeData setValue: @"Re:" forKey:@"title"];

[self.filtered addObject:nodeData];

NSLog(@"SHOW UPDATED FILTERED %@", self.filtered);

}

最佳答案

我假设这条线

_filtered = [self.messages filteredArrayUsingPredicate:pFinal];

是问题所在。您直接访问 ivar,避免调用属性 setter 。这不会增加保留计数。替换为 self.filtered = [self.messages FilteredArrayUsingPredicate:pFinal];

关于ios - Obj-c - 将 NSDictionary 添加到 NSMutableArray?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54831161/

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