aryaxt aryaxt - 1 month ago 16
Swift Question

Parse - Subclassing with Swift?

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

Bridging-Header.h

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


Subclass

class Event: PFObject, PFSubclassing {

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

override class func load() {
registerSubclass()
}
}


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

Any suggestions?

Answer

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;