首页 > 解决方案 > 获取用户作为指针时访问用户名属性时出现PFUser错误

问题描述

收到此错误:

'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;

标签: iosobjective-cparse-platformback4app

解决方案


发生这种情况的原因有两个:

  • 在您尝试检索的用户上设置了 ACL,因此没有被检索。所以请检查您在用户对象上的 ACL。
  • 您没有在查询中使用 .includeKey() 方法。对于 includeKey(),请查看下面的本指南。

https://docs.parseplatform.org/ios/guide/


推荐阅读