鉴于:
MyObject *object1 = [MyObject createWithName:@"name1"];
MyObject *object2 = [MyObject createWithName:@"name2"];
MyObject *object3 = [MyObject createWithName:@"name3"];
NSArray *myArray = @[object1, object2, object3];
NSString *name = @"name1";
正在做
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"name == '%@'", name];
NSArray *filtered = [myArray filteredArrayUsingPredicate:predicate];
留给我
filtered.count == 0
但
NSPredicate *predicate = [NSPredicate predicateWithFormat:
[NSString stringWithFormat:"name == '%@'",name]];
NSArray *filtered = [myArray filteredArrayUsingPredicate:predicate];
留给我
[filtered objectAtIndex:0] == object1
为什么?对于 predicateWithFormat 来说,这似乎是一种奇怪的行为。NSPredicate 对格式的定义是否与 NSLog/NSString 不同?我在文档中找不到任何明显的东西。
提前致谢!