使用KVC取得私有成员变量时报连线错误

KVC--keyPath和key的区别


setValue: forKey

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

setValue: forKeyPath

  • keyPath可以后面加.来拼接键
    • 如 label.text

错误案例示范

  • forKey不能用`.``拼接键,只能放一个键
 [self setValue:[UIColor grayColor] forKey:@"placeholderLabel.textColor"];
  • 报错信息如下:
[<LNLoginRegisterTextField 0x7fbcc3788600> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key placeholderLabel.textColor.'
  • 报错信息释义
[<错误所在类名 0x7fbcc3788600> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key 找不到的键.'
原文地址:https://www.cnblogs.com/KrystalNa/p/4796868.html