我想创建自定义的PFObject类,但它给了我一个非常混乱的错误"属性self.photo未在super.init调用"
初始化这是我的自定义类的代码:
import Foundation
import Parse
class Wish: PFObject, PFSubclassing {
var id: String?
var name: String?
var descriptionWish: String?
var photo: UIImage
var photoThumbnail: UIImage
var amount: Double?
var amountDonated: Int?
static func parseClassName() -> String {
return "Wish"
}
override init() {
super.init()
}
convenience init(id: String?, name: String?, descriptionWish: String?, photo: UIImage, photoThumbnail: UIImage, amount: Double?, amountDonated: Int?) {
self.init()
self.id = id
self.name = name
self.descriptionWish = descriptionWish
self.photo = photo
self.photoThumbnail = photoThumbnail
self.amount = amount
self.amountDonated = amountDonated
}
}
有关如何为此课程制作自定义初始值设定项的任何想法? 我想这样打电话给我的愿望课:
Wish(id: "123", name: "xxx", descriptionWish: "Lorem ipsum", photo: photoImage, photoThumbnail: photoImageThumbnail, amount: 22.20, amountDonated: 10)
并像这样投射PFObject
let wish = myPfObject as Wish
任何帮助表示赞赏!!!
答案 0 :(得分:5)
尝试将您的子类更新为以下内容。请注意您添加到NSManaged
子类的Parse属性的Wish
个关键字以及super.init()
您可能还希望尝试使用Parse提供的UIImage
属性替换PFFile
属性。您可以使用PFImageView
框架中包含的ParseUI
轻松存储和加载图片。
import Foundation
import Parse
class Wish: PFObject, PFSubclassing {
// MARK: - Parse Core Wish Properties
@NSManaged var id: String?
@NSManaged var name: String?
@NSManaged var descriptionWish: String?
@NSManaged var photo: UIImage
@NSManaged var photoThumbnail: UIImage
@NSManaged var amount: Double?
@NSManaged var amountDonated: Int?
// MARK: - Lifecycle
override class func initialize() {
struct Static {
static var onceToken : dispatch_once_t = 0;
}
dispatch_once(&Static.onceToken) {
self.registerSubclass()
}
}
static func parseClassName() -> String {
return "Wish"
}
convenience init(id: String?, name: String?, descriptionWish: String?, photo: UIImage, photoThumbnail: UIImage, amount: Double?, amountDonated: Int?) {
self.init()
self.id = id
self.name = name
self.descriptionWish = descriptionWish
self.photo = photo
self.photoThumbnail = photoThumbnail
self.amount = amount
self.amountDonated = amountDonated
}
}