问题描述
出现此错误:
'NSInternalInconsistencyException',reason: 'Key "username" has no data. Call fetchIfNeeded before getting its value.'
我有一个包含 PFUser
作为指针的联合类。当我从联合类中获取用户时,它只有预期的指针,但这种情况失败并导致上述错误:
if (user.username != nil) {
username = user.username ?? "no username"
}
/** THE ACCESSING property
The username for the `PFUser`.
*/
@property (nullable,nonatomic,strong) Nsstring *username;
解决方法
发生这种情况的原因有两个:
- 在您尝试检索的用户上设置了 ACL,因此它 未被检索。因此,请检查您对用户对象的 ACL。
- 您没有在查询中使用 .includeKey() 方法。为了 includeKey() 看看下面的这个指南。