Search code examples
swiftamazon-web-servicesaws-appsync-ios

DataStoreError: The operation couldn’t be completed. (SQLite.Result error 0.)


I am using AWS Appsync, AWS datastore, Aws Cognito, Aws API. When I am trying to save data on AWS Datastore it gives me this error

DataStoreError: The operation couldn’t be completed. (SQLite.Result error 0.).

let msg = Message.init(....)
//where Message is genrated from amplify codegen models
print(msg) // Output Message()
Amplify.DataStore.save(msg) { result in
    print(msg)// Output Message()
    switch result {
    case .success:
        print("Post saved successfully!")
    case .failure(let error):
        print("Error saving post \(error)")
    }
}

I also get this response in my console.

[SQLiteStorageEngineAdapter] insert into Message (.....) values (NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)

I have created another sample project using the same model and it works fine there.


Solution

  • After spending 8 - 9 days found this. Target < Project Name < Build Settings < Reflection Metadata level. Make sure you select "All" in this.enter image description here

    This setting controls the level of reflection metadata the Swift compiler emits.

    All: Type information about stored properties of Swift structs and classes, Swift enum cases, and their names, are emitted into the binary for reflection and analysis in the Memory Graph Debugger.

    Without Names: Only type information about stored properties and cases are emitted into the binary, with their names omitted. -disable-reflection-names

    None: No reflection metadata is emitted into the binary. Accuracy of detecting memory issues involving Swift types in the Memory Graph Debugger will be degraded and reflection in Swift code may not be able to discover children of types, such as properties and enum cases. -disable-reflection-metadata.

    In my case that was in None. Please make sure you select "All".