Search code examples
iosobjective-cparse-platformback4app

Getting PFUser error when accessing username property when getting user as pointer


Getting this error:

'NSInternalInconsistencyException', reason: 'Key "username" has no data.  Call fetchIfNeeded before getting its value.'

I have a joint class which contains PFUser as pointer. When I get a user from the joint class it just have pointer as expected but this condition fails and leads to error above:

if (user.username != nil) {
   username = user.username ?? "no username"
} 

/** THE ACCESSING property 
 The username for the `PFUser`.
 */
@property (nullable, nonatomic, strong) NSString *username;

Solution

  • This can happen due to two reasons:

    • Either an ACL is set on the user you are trying to retrieve, hence it is not being retrieved.So please check your ACL on the user object.
    • You are not using the .includeKey() method with your query. For the includeKey() have a look at this guide below.

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