我正在尝试将AWS Amplify DataStore集成到我的Swift应用程序中。但是我继续得到这个错误实例方法'save(_:where:completion :)'要求'PostModel'符合'Model'。这是什么意思?
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)")
}
}
}
}
实例方法'save(_:where:completion :)'要求'PostModel'符合'Model'
这是邮政模型
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
}
答案 0 :(得分:1)
您必须使PostModel
符合Model
协议
struct PostModel: Model, Decodable { // add the conformance
// add the protocol requirements...
}