swift - 解析 PFUser 未注册子类

标签 swift macos parse-platform pfuser

我正在尝试在 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/

相关文章:

swift - 如何使用 Swift 协议(protocol)扩展来创建可以修改私有(private)属性的共享代码?

javascript - 如何修复 Chrome 浏览器扩展中的 Native Host Has Exited 错误 -- Native Messaging

ios - 如何更改 UIButton : The signup button in Parse`s PFLoginViewController 的颜色

swift - Facebook(登录 4.27)未返回 Swift 应用程序

ios - 与 Swift StreamVideo SDK 命名冲突

ios - 如何在 GitHub for iOS (SWIFT) 项目中隐藏 API key ?

ios - UiCollectionView 在保存对象时没有选择正确的单元格 Parse.com

c++ - 如何在 Mac 上安装 VTK?

macos - 您可以在 Mac App Store *之外*分发 Safari App Extension 吗?

arrays - 解析将字符串添加到数组 swift