How to get RLMPermissionUser in Realm-Cocoa


#1

The sample code for permissions using the new partial sync here https://docs.realm.io/platform/using-synced-realms/access-control#realm-level

looks like
[realm transactionWithBlock:^{
// Create the role
RLMPermissionRole *readOnlyRole = [RLMPermissionRole createInRealm:realm withValue:@[@“read-only”]];

// Add the user to the role
RLMPermissionUser *user = getUser();
[readOnlyRole.users addObject:user];

// Create a new permission object for the role and add it to the Realm permissions
RLMPermission *permission = [RLMPermission permissionForRoleNamed:readOnlyRole.name onRealm:realm];
permission.canRead = YES;
permission.canQuery = YES;
}];

but there is no function getUser() in realm objective-c. How do you get an RLMPermissionUser from an RLMSyncUser?


#2

When I run the example code substituting some code for getUser()

       [_storedDataManager.connectedRemoteRealm transactionWithBlock:^{
           // Create the role
           RLMPermissionRole *readOnlyRole = [RLMPermissionRole createInRealm:_storedDataManager.connectedRemoteRealm withValue:@[@"read-only"]];
           // Add the user to the role
           RLMSyncUser *currentUser = [RLMSyncUser currentUser];

           RLMPermissionUser *permissionUser = [RLMPermissionUser userInRealm:_storedDataManager.connectedRemoteRealm withIdentity:currentUser.identity];

           [readOnlyRole.users addObject:permissionUser];

           // Create a new permission object for the role and add it to the Realm permissions
           RLMPermission *permission = [RLMPermission permissionForRoleNamed:readOnlyRole.name onRealm:_storedDataManager.connectedRemoteRealm];
           permission.canRead = YES;
           permission.canQuery = YES;
       }];

I get the error:
2018-04-26 13:30:09.329922-0400 BasicAlpsDemo-swift[928:317196] *** Terminating app due to uncaught exception ‘RLMException’, reason: ‘Object type ‘RLMPermissionRole’ is not managed by the Realm. If using a custom objectClasses / objectTypes array in your configuration, add RLMPermissionRole to the list of objectClasses / objectTypes.’