1
votes

For our current game we're using the Parse Local Datastore and pinning the query results from the server, mainly querying for users, characters and challenges (the last two are custom classes). The challenge object has a pointer to the creator, the recipient, and a character. In Xcode we have created the class "Friend" as a subclass of PFUser, "Challenge" as a subclass of PFObject (referencing the "Challenge" parse class), and "CharacterCard" as a subclass of PFObject as well (referencing the "CharacterCard" parse class).

Once the pinned Challenges have been cast to a "Challenge" (my subclass), we then get some information from it and try to retrieve the "userTo", "userFrom", and the "character" (all three are pointers). When doing the following the "userFrom" seems to populate and cast properly, but the "character" does not get assigned anything:

let gm = GameManager.sharedManager
challenge = gm.oldChallenges[indexPath.row]

let friend = challenge.userFrom as! Friend
cell.friendPic.image = friend.profilePic //casts properly, does as expected

let character = challenge.character as! CharacterCard
cell.characterPic.image = UIImage(data: character.thumbnail) //produces an error saying Key "thumbnail" has no data.  Call fetchIfNeeded before getting its value

One thing I noticed is when printing the Challenge object:

CHALLENGE: <Challenge: 0x145dd3810, objectId: AiQgbc6ixN, localId: (null)> {
attempts = 0;
character = "<CharacterCard: 0x145ddc0b0, objectId: fwgW9SbMdD, localId: (null)>";
characterName = Blue;
deletedByFrom = 0;
deletedByTo = 0;
played = 0;
userFrom = "<MyGame.Friend: 0x145d63e10, objectId: WutVKzF0Yh, localId: (null)>";
userFromFBID = 10156116668365451;
userFromName = "Jesus Sainz";
userTo = "<MyGame.Friend: 0x145e7d140, objectId: JrkFYMaQ5P, localId: (null)>";
}
Character: <CharacterCard: 0x145ddc0b0, objectId: fwgW9SbMdD, localId: (null)> {
}
friend fbName: Jesus Sainz

Both the Challenge and the Character simply say "Challenge" and "CharacterCard", whereas the users say "MyGame.Friend". Could this mean that the code is recognizing Friend as a subclass but not the others? (I can successfully cast from PFObjects but not from pointers in everything other than the users).

Why can I cast a "user" pointer to a Friend but not cast a "character" pointer to a CharacterCard??

I would normally just give up and do a normal query to the local datastore (which does return the correct values), but if I can do the cast with the "user"s something tells me I can do it with the "character"s, which would make my live a hell of a lot easier.

Thank you for the help!

1

1 Answers

1
votes

Incredible... I've been wrestling with this for days and in a matter of minutes of posting this I found the solution...

I thought by simply having the characters be pinned that should be enough to access them, but it seems the only thing I needed to do was simply create an array of the pinned characters from the challenges (query from local datastore).

I'm actually still confused as to why this solved the issue since I'm not really accessing that array explicitly to get the information, but it appears that just having that array seems to allow me to cast the pointer to the CharacterCard. Weird... but I hope this helps someone.