Dziwne zachowanie KVC
Dlaczego ten kod działa poprawnie:
NSArray* arr = @[[CALayer layer], [CALayer layer]];
NSString *sumKeyPath = @"@sum.bounds.size.width";
CGFloat totalSize = [[arr valueForKeyPath:sumKeyPath] floatValue];
Ale ten kod zawiera błąd:
NSArray* arr = @[[UIImage imageNamed:@"img1"], [UIImage imageNamed:@"img2"]];
NSString *sumKeyPath = @"@sum.size.width";
CGFloat totalSize = [[arr valueForKeyPath:sumKeyPath] floatValue];
Błąd: [NSConcreteValue valueForUndefinedKey:]: ta klasa nie jest zgodna z kodowaniem wartości klucza dla szerokości klucza.
NSArray* arr = @[[UIView new], [UIView new]];
NSString *sumKeyPath = @"@sum.bounds.size.width";
CGFloat totalSize = [[arr valueForKeyPath:sumKeyPath] floatValue];
podaj ten sam błąd