Multiple subclasses of the same subclass of PFObject that cause errors

I have this very simple setup for my subclasses of PFObject in Swift.

  • Foo: PFObject
  • Bar1: Foo
  • Bar2: Foo

Here's what they look like in code:

Foo

import Foundation class Foo : PFObject, PFSubclassing { class func parseClassName() -> String! { return "Foo" } } 

Bar1

 import Foundation class Bar1 : Foo {} 

BAR2

 import Foundation class Bar2 : Foo {} 

AppDelegate didFinishLaunching

 Foo.registerSubclass() Bar1.registerSubclass() Bar2.registerSubclass() Parse.setApplicationId("APP_ID", clientKey: "CLIENT_KEY") 

Then I get this error at runtime:

 Tried to register both _TtC9CardForge4Bar1 and _TtC9CardForge4Bar2 as the native PFObject subclass of Foo. Cannot determine the right class to use because neither inherits from the other. 

It seems like I can't have multiple subclasses of the same subclass of PFObject , but I don't see anything in the documentation. What's going on here? What is a custom subclass?

+6
source share
2 answers

I do not think you can do this. I do not understand where you want to go by doing this.

I think the best approach for a subclass in parsing is one subclass for one table. The most important subclass task for Parse is to manage your properties. Therefore copy ALL of your custom properties into your own class. And just register this subclass. After that, you can create another subclass (not registered for parsing) for methods or protect your properties.

0
source

As in Parse iOS SDK 1.6.2, I can confirm that you can have subclasses of subclasses of PFObject , and they work fine.

i.e. it is possible to have class Foo : Bar and class Bar : PFObject , and you can save objects of type Foo and request them as well. It just works.

0
source

Source: https://habr.com/ru/post/971837/


All Articles