提问人:alch_coder 提问时间:7/24/2022 最后编辑:Asperialch_coder 更新时间:7/26/2022 访问量:813
从非协议类型“PFObject”继承
Inheritance from non-protocol type 'PFObject'
问:
我在尝试创建模型时在带有 Swift 的 Xcode 上收到此错误,这是模型的代码:Inheritance from non-protocol type 'PFObject'
import Foundation
import ParseSwift
import Parse
import SwiftUI
struct Category: ParseObject, PFObject {
// Required properties from ParseObject protocol
var originalData: Data?
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
// Custom fields for the contact's information
var name: String = ""
var cover: String = ""
var color: String = ""
var createdBy: String = ""
}
extension Category {
init(name: String, cover: String, color: String, createdBy: String) {
self.name = name
self.cover = cover
self.color = color
self.createdBy = createdBy
}
}
我做错了什么?
答:
0赞
CoreyB
7/26/2022
#1
看起来您正在尝试同时使用 Parse-Swift 和 Parse Objective-C SDK,这是您不应该做的。你是使用 Parse-Swift 设置的,所以假设这是你想要使用的内容,删除,你的 Parse 对象应该如下所示:ParseObject
import Parse
import Foundation
import ParseSwift
import SwiftUI
struct Category: ParseObject {
// Required properties from ParseObject protocol
var originalData: Data?
var objectId: String?
var createdAt: Date?
var updatedAt: Date?
var ACL: ParseACL?
// All Custom fields should be optional
var name: String?
var cover: String?
var color: String?
var createdBy: String?
}
extension Category {
init(name: String, cover: String, color: String, createdBy: String) {
self.name = name
self.cover = cover
self.color = color
self.createdBy = createdBy
}
}
从项目中完全删除依赖项,因为根本不使用或根本不需要它。Parse-Swift 中的 playground 展示了如何正确使用 SDK 以及使用 SDK 所需的任何导入。Parse
Parse-Swift
评论