簡體   English   中英

解析PFUser未注冊子類

[英]Parse PFUser not registering subclass

我正在嘗試在OSX桌面軟件中使用Parse PFUser。 當我嘗試使用它PFUser.query()時,它會顯示一條消息: Failed to set (contentViewController) user defined inspected property on (NSWindow): The class PFUser must be registered with registerSubclass before using Parse.

它是在沒有注冊課程的情況下發生的。

我嘗試通過以下方式注冊該類: 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)
        })
    }
}

在Internet上閱讀一些內容后,我發現在OSX中,ViewController在AppDelegate完成加載之前就已啟動,因此我在ViewController's viewDidLoad而不是AppDelegate中初始化了Parse連接並進行了子類化,它工作正常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM