2
votes

I am implementing parse into my swift application. I have subclasses, where a subclass has a member object that is another parse subclass. When I try to access the object, the application gets a "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[fve.Workout sets]: unrecognized selector sent to instance 0x1740d0d10'"

Any idea how I can access elements of a PFObject subclass that are PBObject subclasses themselves?

Here is how i declared the objects:

class Workout: PFObject, PFSubclassing {
    @NSManaged var date: NSDate
    @NSManaged var workoutTime: Int
    @NSManaged var sets: [ExerciseSet]
    ...
}

class ExerciseSet: PFObject, PFSubclassing {
    @NSManaged var exercise: Exercise
    @NSManaged var sets: [SingleSet]
    ...
}

And this causes a crash when I try to access the field:

for workout in historicalWorkoutsParse {
    println("workout \(workout)")
    let exerciseSets = workout.sets
    println("exerciseSet: \(exerciseSets)")
}

Even though I do see that the data exist in the object:

workout <Workout: 0x1740cf8f0, objectId: A3218Oxiuh, localId: (null)> {
    date = "2015-09-05 19:39:43 +0000";
    sets =     (
        "<ExerciseSet: 0x1740cf960, objectId: V54sAUKSMf, localId: (null)>"
    );
    user = "<PFUser: 0x174109240, objectId: LbeTd8GqwU, localId: (null)>";
    workoutTime = 0;
}

Thanks!

3

3 Answers

3
votes

If you use PFSubclassing you need to call registerSubclass before you can use the class. Also it has to be done before the Parse.setApplicationId call:

Workout.registerSubclass()
ExerciseSet.registerSubclass
//Parse.setApplicationId
2
votes

You must call Exercise.registerSubclass() BEFORE Parse.setApplicationId("YOUR_APPLICATION_ID") in application:didFinishLaunchingWithOptions:

You also need to override parseClassName in your custom subclass

2
votes

Parse didn't seem to like that I was using "sets" as the object name. When I changed it to "exerciseSet" it seemed to work (it also worked when i accessed it as a dictionary... workout["sets"])