Parse.com object disappears after saving - ios

This is a bit of a crazy one. I have an IOS app that saves an object to Parse.com's datastore. Until a couple of days ago everything worked well. Now, suddenly, the object is not going into the database. I would put the code here but it doesn't seem to be the issue, as it gets even more bizarre:
When I go directly to the data browser and insert a row manually, it shows up right there.
But when I refresh the data browser -- the object is gone.
Looking at the forums here's some more data:
When I save from the app, I have an existing current user.
The object itself exists.
The permissions on my class are all "Public."
The app codes are correct (I'm able to read from the database.)
I'm even seeing the saveInTheBackground success block getting called, and printing out the object it has a valid object id!!!
But then it goes pooooooffff and is gone.
Any idea what's happening?
EDIT: I added a different class with the exact same columns, changed the appropriate fields in the app, and now everything works. But this is obviously alarming, that a class stops saving objects all of a sudden. Any idea why?

Related

Reset new coredata managed object to a staged state

Hi fellow iOS developers, I have seem to run into a roadblock here with coredata and Im fairly certain this is should be a common use case. But I am either not querying google correctly or my design with handling managed objects was bad which led to this problem.
So basically, the problem that I am facing is the following..
User creates a new managed object object.
User updates said new managed object object (say edit the name
field)
** The following is the problem **
User wants to edit the same field again, but decides to discard their changes
What is the right thing to do here? Initially I was using .refresh() on the managed object context, but that only works if the object is persisted in the database.
Essentially, I don't want to save the object until the user explicitly opts to "save". Which leaves me in this limbo land. At first one of my thoughts was to created regular objects and convert them into core data objects when "save" is selected. However, that proved to be inefficient especially when handling multiple relationships.
I would think that there is something that is provided that aims to solve this problem, im just not quite querying google correctly.

Delete posts after a certain time, even when user isn't using the app

I'm using Swift on iOS and Firebase
I am trying to find a way to delete a post when it was shared more than X hours ago, no matter if the user is connected on the app, or not.
For that I have set a time stamp for my post object, which gives the date/time when the post is initially created.
I thought about adding a "timer" to my post node, that would be updated every second. The problem with that is that I would need for that to make a request to my database every second, and this would obviously be very data consuming.
I googled a lot and it seems like the only way of doing this is using some server-side code in Javascript using Google Functions, and I read the documentation but I still have no idea how I can do that and can't barely find anything refering to it.
Do you have an idea how to solve this problem?
Thanks!

Core Data - partial data loss when relaunching app

I have a Core Data app with a single model consisting of several entities. For the purposes of this question, let's call the model "Person" and have the entities "name" (string), "age" (int), "occupation" (string), and "description" (string).
As an example, I may add a new Person. I set their name, age, occupation, and description. I confirm that the context has been updated by checking the contents of the NSManagedObjectContextObjectsDidChangeNotification userInfo. The context is then saved and persisted to disk (confirmed through both logging and querying the SQLite db).
At this point, I can edit any of my Person objects and all entities can be modified, added, deleted, etc., and all changes are confirmed to change the context with NSManagedObjectContextObjectsDidChangeNotification and confirmed to be persisted to disk via logging and querying SQLite - everything works as expected.
However, "occupation" and "description" do not persist after relaunching the app. They are not set as transient (however they are "optional"), and the main context is saved (sometimes several times) after they are set. More so, if I quit the app, before opening it again, I can query the SQLite db and confirm that the changes still exist on disk.
When the app is reopened, I can confirm that all is the same on disk as it was when I quit. However, when I initialize Core Data in my App Delegate, NSManagedObjectContextObjectsDidChangeNotification notifies me that something has changed. For some reason, "occupation" and "description" have disappeared. They haven't been set to null, they've been set to zero-length strings. Therefore, next time something happens that triggers a save, "occupation" and "description" are set to zero-length strings and disappear. This all happens just on launch - I do not access a view controller or anything else that even queries for those specific fields. I do, however, show a view controller that does require a fetch request that populates a UITableView that displays the People objects, although it does not specifically display either of the entities in question.
There is a lightweight Core Data Model migration from Person 1 to Person 2, however, when switching back to Person 1, this problem persists, leading me to believe it is not the migration which is an issue.
I'm asking for recommendations on where to start troubleshooting this issue. I can't post code - I have no idea where in my app the problem is occurring. I've tried to troubleshoot as much as possible with confirming when changes occur in the context and how that compares with what is on disk, I just don't know where to go from here. I don't know why these entities (and only some of them) are disappearing. How would someone start troubleshooting this kind of issue? Any help is appreciated.
Thanks to the guidance of #Rog and #Avi, I was able to both set up custom setters for the properties in question and override validateValue:forKey:error, and set breakpoints in each. From here, I was able to see the calling methods and diagnose the issue correctly.
The actual issue was that I was misunderstanding that initWithEntity:insertIntoManagedObjectContext: is called for each object when Core Data is initialized, where I was under the impression it would only be called when an object is initially created (once and only once). The problematic code was in initWithEntity:insertIntoManagedObjectContext:.
Thank you for your help!

Objects set to nil after initial interaction

I am a pretty knowledgable iOS dev and I feel stupid for not being able to figure this out. I am currently working on a new app that upon launch checks for the last user, sets this property on the AppDelegate as well as the users's company property. These items are stored in Core Data. On the AppDelegate I have overridden the setter for the Company property to make a network request as I need to perform a fetch every time this is set. The request goes through fine but when the call comes back (Im using AFNetworking 2) and I begin to parse the info and perform some actions on it, the responseObject is nil'd out. I feel like this should be pretty obvious but I cannot figure it out. Any help would be appreciated. I have tried to assign the response to a new property and variable, with and without copying the actual object.

PFObject getting corrupted somewhere in the app when calling cloud code

Okay, I promise I couldn't have come up with a better title. I'm on the latest (1.6.4) Parse iOS SDK and I roughly have a Post class with a comments field which is a number. I call a cloud function, and upon completion, my post object's fields are gone. Anything other than the objectId is nil. If I fetch (forcefully, ifNeeded doesn't work as well) then it loads again. But meanwhile, my client-side data gets corrupted. This happens on PFUser class too, and it happens only after calling something at the cloud. Am I doing something wrong, or is it a very serious bug at Parse iOS SDK?
I am also using local datastore (since my whole app has many calls to it, I can't just disable and test it), if it helps.

Resources