2017-08-18 56 views
0

我想在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未注册子类

这是在没有注册类的情况下发生的。

我试着用这种方式注册类: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) 
     }) 
    } 
} 

回答

0

阅读中,我发现在互联网上的一些内容在OSX中,ViewController将在bef中启动AppDelegate完成加载,所以我初始化了Parse连接并在ViewController's viewDidLoad中创建了子类化,而不是AppDelegate,它工作得很好。