creatorUserRecordID.recordName contains "__defaultOwner__" instead of UUID shown in Dashboard

1.1k Views Asked by At

Downloading a CKRecord from CloudKit and when plotting creator recordName, I can see this:

(lldb) po record.creatorUserRecordID.recordName
__defaultOwner__

but, Dashboard show a real value.

enter image description here

Why the difference?!

I hope I do not have to download only because of this the logged in user first?!

2

There are 2 best solutions below

1
On

it is a bug

edit this:

- (void)postMoodFeed:(NSString *)moodFeed
{
    CKRecord *moodRecord = [[CKRecord alloc] initWitenter code herehRecordType:@"Mood"];
    moodRecord[@"moodFeed"] = moodFeed`enter code here`

    [[[CKContainer defaultContainer] publicCloudDatabase] saveRecord:moodRecord completionHandler:^(CKRecord *record, NSError *error) {
        [self queryMyMood];
    }];
}

- (void)queryMyMood
{
    // currentUserRecordID is fetched from fetchUserRecordIDWithCompletionHandler: of CKContainer
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"creatorUserRecordID = %@", currentUserRecordID];

    CKQuery *query = [[CKQuery alloc] initWithRecordType:@"Mood" predicate:predicate];

    [[[CKContainer defaultContainer] publicCloudDatabase] performQuery:query inZoneWithID:nil completionHandler:^(NSArray *results, NSError *error) {
        if (results) {
            for (CKRecord *eachRecord in results) {
                // Following logs are all __defaultOwner__
                NSLog(@"%@", eachRecord.creatorUserRecordID.recordName);
                [[[CKContainer defaultContainer] publicCloudDatabase]fetchRecordWithID:eachRecord.creatorUserRecordID completionHandler:^(CKRecord *record, NSError *error) {
                    // All following logs are "Unknown item" error
                    NSLog(@"%@", error);
                }];
            }
        }
    }];
}
2
On

__defaultOwner__ mean's it's owned by the currently logged in iCloud account. So you could could check for that and display "Me" or the person's name if you have it. If you need to find out the logged-in user's recordID you can use the async method: fetchUserRecordIDWithCompletionHandler.