swiftmacosparse-platformpfuser

Parse PFUser not registering subclass


I am trying to use Parse PFUser in a software for OSX desktop. When I try to use it PFUser.query() it gives a message: Failed to set (contentViewController) user defined inspected property on (NSWindow): The class PFUser must be registered with registerSubclass before using Parse.

It is happening without registering the class.

I tried it registering the class this way: PFUser.registerSubclass() but it still doesn't work.

I will use the default PFUser without adding any fields to it, so I don't need to create a custom class to be my PFUser.

I tried to use PFUser.enableAutomaticUser() without success

Code below:

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)
        })
    }
}

Solution

  • Reading some content on the internet I discovered that in OSX the ViewController is launched before the AppDelegate finishes loading, so I initialized the Parse connection and subclassing in the ViewController's viewDidLoad instead of AppDelegate and it is working just fine.