I am getting this error Inheritance from non-protocol type 'PFObject'
on Xcode with Swift while trying to create a Model, here is the code of the model:
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
}
}
What am I doing wrong?
CodePudding user response:
It looks like you are trying to use Parse-Swift and the Parse Objective-C SDK at the same time which you shouldn't be doing. Your ParseObject
is setup using Parse-Swift so assuming that's what you want to use, remove, import Parse
and your Parse Object should look like:
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
}
}
Remove the Parse
dependency completely from your project as Parse-Swift
doesn't use or need it at all. The playgrounds in Parse-Swift show how to use the SDK correctly along with any imports that are needed to use the SDK.