我正在尝试在 OSX 桌面软件中使用 Parse PFUser。当我尝试使用它 PFUser.query() 时,它会给出一条消息:无法在(NSWindow)上设置(contentViewController)用户定义的检查属性:在使用 Parse 之前,必须使用 registerSubclass 注册 PFUser 类。
它是在没有注册类(class)的情况下发生的。
我尝试以这种方式注册类:PFUser.registerSubclass()
,但它仍然不起作用。
我将使用默认的 PFUser,而不向其中添加任何字段,因此我不需要创建自定义类来作为我的 PFUser。
我尝试使用PFUser.enableAutomaticUser()
但没有成功
代码如下:
AppDelegate.swift
import Cocoa
import Parse
import Bolts
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
let APP_ID = "app_id"
let CLIENT_KEY = "client_key"
let SERVER = "https://parseserver.com/"
func applicationDidFinishLaunching(_ aNotification: Notification) {
PFUser.registerSubclass()
let configuracaoParse = ParseClientConfiguration {
$0.applicationId = self.APP_ID
$0.clientKey = self.CLIENT_KEY
$0.server = self.SERVER
}
Parse.initialize(with: configuracaoParse)
}
func applicationWillTerminate(_ aNotification: Notification) {
// Insert code here to tear down your application
}
}
ViewController.swift
import Cocoa
import Parse
class ViewController: NSViewController {
@IBOutlet weak var emailTextField: NSTextField!
@IBOutlet weak var senhaSecureTextField: NSSecureTextField!
override func viewDidLoad() {
super.viewDidLoad()
contaUsuarios()
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
@IBAction func entrarButtonClicked(_ sender: NSButton) {
}
func contaUsuarios() {
let query = PFUser.query()
query?.countObjectsInBackground(block: {
(count, error) -> Void in
let numeroUsers = Int(UInt32(count))
if numeroUsers > 0 {
}
print(numeroUsers)
})
}
}
最佳答案
阅读互联网上的一些内容,我发现在 OSX 中,ViewController 在 AppDelegate 完成加载之前启动,因此我在 ViewController 的 viewDidLoad
而不是 AppDelegate 中初始化了 Parse 连接和子类化,并且它正在工作就好了。
关于swift - 解析 PFUser 未注册子类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45765695/