gpt4 book ai didi

ios - 从数组中删除对象不会删除任何东西

转载 作者:行者123 更新时间:2023-11-28 20:10:25 25 4
gpt4 key购买 nike

我有:

self.path = [self pathByCopyingFile:@"Notes List.plist"];
self.data = [[NSMutableDictionary alloc] initWithContentsOfFile:self.path];
self.notes = [self.data objectForKey:@"Notes"];

然后在一个按钮中(肯定会调用 Button 方法):

NSString *title = self.navigationItem.title;
//Filter notes array by title
NSPredicate *pred = [NSPredicate predicateWithFormat:@"Title =[cd] %@", title];
NSArray * titleArray = [self.notes filteredArrayUsingPredicate:pred];

//delete all the notes with the old title name
[self.notes removeObject:titleArray];
NSLog(@"%@", self.notes);

此时,self.notes 仍然包含这些项目,我不知道为什么它们没有被删除

最佳答案

您正试图从数组中删除一个数组。那不是你想要的。我相信您的目标是从 notes 数组中删除 titleArray 中的所有对象。

这甚至没有考虑 self.notes 可能是 NSArray 而不是 NSMutableArray

如果 self.notes 是可变的,您可以使用 removeObjectsInArray:

[self.notes removeObjectsInArray:titleArray];

关于ios - 从数组中删除对象不会删除任何东西,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20550966/

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