在 swift 中,我使用这段代码获取特定对象的特定值
if let layer = self.layers.first(where: {$0.id == id}) { }
我想在 objective-c 中使用它。我应该如何从对象数组中获取特定值的对象
最佳答案
您可以在 Objective-C
中使用 NSPredicate
来过滤数组。
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"id == %@", id];
id layer = [[self.layers filteredArrayUsingPredicate:predicate] firstObject]
关于ios - 如何从数组中获取特定值的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50485665/