aryaxt aryaxt - 1 year ago 93
Swift Question

Parse - Subclassing with Swift?

I'm trying to get a standard subclassing to work with swift.


#import <Parse/Parse.h>
#import <Parse/PFObject+Subclass.h>
#import <Parse/PFGeoPoint.h>


class Event: PFObject, PFSubclassing {

class func parseClassName() -> String! {
return "Event"

override class func load() {

getting a compile error saying that Event does not conform to PFSubclassing.

Any suggestions?

Answer Source

Check out this thread. Here is an explanation of the problem:

I already opened a bug to Parse about this point. Basically the issue is with the Parse header files where the protocol definition inside PFSubclassing.h defines this method in this way: + (instancetype)objectWithoutDataWithObjectId:(NSString )objectId; but then the same method is implemented by PFObject+Subclass.h in this way (notice the difference: instancetype --> id) + (id)objectWithoutDataWithObjectId:(NSString )objectId; This is enough for Swift to complain. The only solution I found is to directly change the header in the framework definition by replacing "id" with "instancetype". If you do this, the code will compile.

So, here's your solution, and it's worked for me; I had the same problem:

  • Open PFSubclassing.h (note that this is the PFSubclassing.h under your Parse directory)
  • Find the objectWithoutDataWithObjectId: method
  • Replace the method signature with: (id)objectWithoutDataWithObjectId:(NSString *)objectId;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download