Reputation: 3573
I have a CKRecordType
with a reference field that I want to set to the current user of the app.
CKRecord * record = [[CKRecord alloc] initWithRecordType:@"UserStatus"];
[record setValue:@"online" forKey:@"status"];
// what user should be?
[record setValue:user forKey:@"user"];
How should I do that?
Upvotes: 1
Views: 169
Reputation: 3573
First, get the userId
:
- (void)getUserId
{
[self.defaultContainer fetchUserRecordIDWithCompletionHandler:^(CKRecordID * _Nullable recordID,
NSError * _Nullable error)
{
if (error == nil)
{
self.userRecordID = recordID;
}
}];
}
Then:
CKRecord * record = [[CKRecord alloc] initWithRecordType:@"UserStatus"];
record[@"status"] = @"online";
CKReference *userReference = [[CKReference alloc] initWithRecordID:self.userRecordID action:CKReferenceActionDeleteSelf];
record[@"user"] = userReference;
Upvotes: 1