Hoping for some insight here. I'm still facing this issue. The Apple Docs don't tell you what you need to include to use an Object so I don't know how to find what to type in without having the autocomplete working.
Post
Replies
Boosts
Views
Activity
Thanks @claude31. Any example code you can give here would be much appreciated.. For more clarity, currently my code looks like this...
Amplify.API.get (request:request)
{
result in switch result
{
case .success(let data):
// Do success stuff
case .failure(let apiError):
// Do failure stuff
}
}
I'm looking to handle that switch block in another function. So I need to change the above to something like this below (with obviously the correct syntax. Example code here would be helpful...
Amplify.API.get (request:request)
{
myFunction(result, myParam1, myParam2)
}
It believe it may have something to do with the listener parameter from the Amplify.API.get function definition but I'm not sure how to do that while still adding in my parameters to my function call.
Sorry, I copied the autofill.. Here's the definition...
func get(request: RESTRequest, listener: RESTOperation.ResultListener?) -> RESTOperation
And here's "RestOperation.ResultListener...
open class AmplifyOperation<Request: AmplifyOperationRequest, Success, Failure: AmplifyError>: AsynchronousOperation {
/// The concrete Request associated with this operation
public typealias Request = Request
/// The concrete Success type associated with this operation
public typealias Success = Success
/// The concrete Failure type associated with this operation
public typealias Failure = Failure
/// Convenience typealias defining the `Result`s dispatched by this operation
public typealias OperationResult = Result<Success, Failure>
/// Convenience typealias for the `listener` callback submitted during Operation creation
public typealias ResultListener = (OperationResult) -> Void
Hoping that helps clarify things? I didn't post all the code as it's not mine...
Additional info here...
This appears to be caused by adding cocoa pods to the project? I simply did pod init, added CocoaAsyncSocket as a pod, did a pod install, and opened the xcworkspace file. When I try to commit I get all those files...
Ok. I think I resolved it...
What it came down to is the referenceAction. This was set backwards. This code from my first code snippet above...
CKReference *gameRef = [[CKReference alloc] initWithRecordID:self.record.recordID action:CKReferenceActionNone]; self.chat[@"game"] = gameRef;
[self.chat setParent:gameRef];
Has the action on the CKReference set to CKReferenceActionNone. This was because when I had this set, correctly, to CKReferenceActionDeleteSelf it would cause a crash with the exception : Parent references must be CKReferenceActionNone with userInfo = (null)
But what I realized is that I had my Chat reference, stored in my Game object set to deleteSelf.
CKReference *chatRef = [[CKReference alloc] initWithRecordID:self.chat.recordID action:CKReferenceActionDeleteSelf]; self.record[@"chat"] = chatRef;
self.record = Game record. Just to clarify.
So in this setup if a chat record was deleted, then the whole game would be deleted. Which was counter to having the Game be the PARENT of the Chat record. Which is why the exception Invalid list of records: Cycle detected in record graph was thrown.
The solution? setParent seems to be a special case. Sending it a CKReference with deleteSelf set is invalid for some reason. Not sure why causes this second error. Perhaps someone can explain that? But the solution is to use ANOTHER CKReference. Or specifically, a different function. I now use setParentReferenceFromRecord on my Chat record.
[self.chat setParentReferenceFromRecord:self.record];
This then correctly sets the parent with a new reference and I have my existing reference. It seems a bit double duty here. I have two fields (a system and custom) with the same data except for the "ReferenceAction". So I believe that if I delete the Game record, my custom field's CKReference with deleteSelf set on the Chat record will cause the cascade. The system record Parent doesn't really apply here. So now I'm left with, why use it???
For clarity for anyone else who comes across this, here is the full code listing of creating my two records again... The code that saves them is unchanged.
CKRecordZoneID *zoneID = [[CKRecordZone alloc] initWithZoneName:GameZoneName].zoneID;
self.record = [[CKRecord alloc] initWithRecordType:@"Game" zoneID:zoneID];
[self setCoreValues:self fromRecord:self.record];
self.record[@"name"] = self.name = theGame.name;
// Make Chat
self.chat = [[CKRecord alloc] initWithRecordType:@"Chat" zoneID:zoneID];
self.chat[@"name"] = theGame.chat.name;
		 CKReference *gameRef = [[CKReference alloc] initWithRecordID:self.record.recordID action:CKReferenceActionDeleteSelf];
self.chat[@"game"] = gameRef;
[self.chat setParentReferenceFromRecord:self.record];
CKReference *gameChatRef = [[CKReference alloc] initWithRecordID:self.chat.recordID action:CKReferenceActionNone];
self.record[@"chat"] = gameChatRef;
Ok I've narrowed the issue down. If my call to setParent on the Chat object (line 13 above of the first code listing). If I remove this line. Everything works and my two references are saved so each record has a reference to each other.
However I believe then that I'm missing the benefits of using setParent? So that when I do an update to a child object things are kept in sync? Or is setParent only to be used when using CoreData/CloudKit syncing that was introduced in 2019 with NSPersistentCloudKitContainer? I'm not using that (as much as I'd like to) because I need to share my records. So I'm doing the Core Data/Cloud Kit syncing myself.