I am attempting to integrate AWS Amplify DataStore into my Swift application. However I keep on getting this error Instance method 'save(_:where:completion:)' requires that 'PostModel' conform to 'Model'. What does this mean?
import Foundation
import Amplify
import AmplifyPlugins
protocol PostingAmplify {
func addPost()
}
extension PostingAmplify {
func addPost() {
let post = PostModel(username: "champ", text: "pog", mediaLink: "pog", year: 1, month: 1, day: 1, hour: 1, minute: 1, second: 1)
Amplify.DataStore.save(
post
) {
switch $0 {
case .success:
print("Added post")
case .failure(let error):
print("Error adding post - \(error.localizedDescription)")
}
}
}
}
Instance method 'save(_:where:completion:)' requires that 'PostModel' conform to 'Model'
This is Post Model by the way
import Foundation
struct PostModel: Decodable {
var username: String
var text: String
var mediaLink: String
var year: Int
var month: Int
var day: Int
var hour: Int
var minute: Int
var second: Int
}
You have to make PostModel
conform to Model
protocol
struct PostModel: Model, Decodable { // add the conformance
// add the protocol requirements...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.