gpt4 book ai didi

ios - 解析子类实例方法 EXC_BAD_INSTRUCTION

转载 作者:行者123 更新时间:2023-11-30 13:49:43 31 4
gpt4 key购买 nike

当从解析用户对象 PFUser 进行子类化时,我在使用自己的方法时遇到了错误指令错误。你们有什么想法为什么会发生这种情况

User.swift

import UIKit
import Parse

class User: PFUser {

// Instance Variables
@NSManaged var photo: PFFile

// Parse Setup
override class func initialize() {
struct Static {
static var onceToken : dispatch_once_t = 0;
}
dispatch_once(&Static.onceToken) {
self.registerSubclass()
}
}

// Instance Methods
func fetchPhoto(callback: (image: UIImage) -> Void) {
guard let url = self.photo.url else {
return
}

let request = NSURLRequest(URL: NSURL(string: url)!)

if let image = Globals.imageCache.imageForRequest(request) {
callback(image: image)
return
}

Globals.imageDownloader.downloadImage(URLRequest: request) { response in
if let image: UIImage = response.result.value {
callback(image: image)

Globals.imageCache.addImage(image, forRequest: request)
} else {
print(response)
}
}
}
}

ViewController.swift

导入UIKit

class ProfileHeaderController: UIViewController {

@IBOutlet weak var avatarButton: UIButton!
@IBOutlet weak var userLabel: UILabel!
@IBOutlet weak var nameLabel: UILabel!

private var user = User.current()

func updateHeader() {
self.userLabel.text = self.user.username
self.nameLabel.text = self.user.fullName

self.user.fetchPhoto { (image) -> Void in
self.avatarButton.setImage(image, forState: .Normal)
}
}
}

最佳答案

是的,您需要在 Appdelegate 中或在调用 Parse.setApplicationId 之前注册子类

这一段文字指出:https://parse.com/docs/ios/guide#objects-subclasses

示例:

Appdelegate.swift
....
User.registerSubclass()
Parse.setApplicationId("appid", clientId:"clientid")

关于ios - 解析子类实例方法 EXC_BAD_INSTRUCTION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34436163/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com