kvo的一些隐藏引用

eg:数组的去重,如何不引用新的对象去重数组

NSArray*array=@[@"1234",@"23",@"abc",@"a",@"abc",@"1234"];
array = [array valueForKeyPath:@"@distinctUnionOfObjects.self"];
NSLog(@"%@", array);

eg 数组的符号操作

NSArray *array = @[@"10",@"5",@"6"];
NSNumber *sum = [array valueForKeyPath:@"@sum.floatValue"];
NSNumber *avg = [array valueForKeyPath:@"@avg.floatValue"];
NSNumber *max = [array valueForKeyPath:@"@max.floatValue"];
NSNumber *min = [array valueForKeyPath:@"@min.floatValue"];

eg.数组字符全部大写

 NSArray *array = @[@"my", @"Mine", @"name", @"Number"];
 NSLog(@"%@", [array valueForKeyPath:@"uppercaseString"]);

eg:改变 UITextfield 的 placeholder 的颜色

[textField setValue:[UIColor whiteColor] forKeyPath:@”_placeholderLabel.textColor”];

更多字符串操作可以自己用到时再查询

/* The following three return the canonical (non-localized) mappings. They are suitable for programming operations that require stable results not depending on the user's locale preference.  For locale-aware case mapping for strings presented to users, use the "localized" methods below.
*/
@property (readonly, copy) NSString *uppercaseString;
@property (readonly, copy) NSString *lowercaseString;
@property (readonly, copy) NSString *capitalizedString;

你可能感兴趣的:(kvo的一些隐藏引用)