KVC forkey 与 forKeyPath的区别

1.setValue: forKey

key只能是一个键,不能拼接

示例:

 [self setValue:"AA" forKey:@"color"];

2.setValue: forKeyPath

keyPath可以后面加.来拼接键

示例:

 [self setValue:[UIColor grayColor] forKeyPath:@"placeholderLabel.textColor"];

错误信息:

setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key placeholderLabel.textColor.'

你可能感兴趣的:(KVC forkey 与 forKeyPath的区别)