shadowmoses
shadowmoses

Reputation: 343

Parse and Swift - previously deleted pointer to nonexistent object keeps reappearing

In my User class on Parse, I have an array of pointer objects. They point to another Parse class, let's call these "Tracker" objects.

In my code, I delete the pointer using removeObject. Next, I delete the object itself with object.delete()

When I refresh the Parse web data browser, both the pointer and the object are gone, so everything seems to be working.

Here is the scenario with a problem:

With a fully clear Parse back-end, I sign up with my app, which automatically logs me in. While logged in, I create 2 "Events", which are objects in Parse. This is working. With each event that a User creates, a pointer is created within an array of their User object. This array of pointers points to those "Tracker" objects I mentioned above.

Next when a User logs in to the another device, or the simulator at the same time, their 2 events are loaded correctly. When the User deletes one of their events, the Parse back-end is updated correctly. 1 Event, 1 tracker object, 1 pointer to the tracker object in the User class. All good.

Now, when the User goes back to their original device, the app prompts them to logout, because the login has expired. All good. Now, here is the problem:

When the user logs back in on the original device, the pointer to the "Tracker" object that was just deleted in the previous step re-appears in the User's array of tracker object pointers. The object itself, the "Tracker" object, does not re-appear though. Most of the time, this causes the app to crash with:

fatal error: NSArray element failed to match the Swift Array Element type

If I manually remove the "ghost" pointer from Parse, and re-run the app, everything behaves as it should.

I have tried running fetch() on the user upon login. Didn't make a difference.

It's as if the User object is being cached or stored locally on the original device, and then when it logs in, it is replacing the data on Parse. I don't see how though.

I'm happy to post screen-shots, code, etc. Please help!

Upvotes: 1

Views: 179

Answers (1)

shadowmoses
shadowmoses

Reputation: 343

I solved it.

It must have been a bug in Parse, because I updated the SDK from 1.9.1 to 1.10.0, and the issue mysteriously went away.

Sucks I wasted ~4 days trying to fix it, but...moving on.

Nothing in the change log seemed obvious that it was relating to my issue..

V1.10.0 — NOVEMBER 19, 2015

NEW

Removed PFObject mutable container tracking. Added generic types to PFUser login/link methods. Added generic type to PFInstallation's channels property. Added generic type to PFPush.getSubscribedChannels... methods. Converted PFUser's isAuthenticated method to a property. Converted PFFile's isDataAvailable, isDirty methods to properties. Converted PFObject's isDataAvailable, isDirty, allKeys methods to properties. Converted PFACL's publicReadAccess and publicWriteAccess methods to properties. IMPROVED

Staged PFFiles are now stored in caches directory. Replaced all nullability annotations via macros with generic ones. Made all access to sqlite thread-safe to mitigate a potential crash. PFPurchase.buyProduct() no longer requires non-nil completion block. Removed usage of nullability specifier on types that support annotations. Improved persistence logic for all local files in preparation for tvOS/watchOS release. Added extra safety guards to mitigate potential crash when buying products via PFPurchase. Keys that are used for query result caching are now generated in consistent order across architectures. FIXED

Fixed a crash on trying to getData/save a PFFile without any local data. Fixed an issue where failed PFUser.linkWithAuthType() would persist wrong information to disk.

Upvotes: 0

Related Questions