How to retrieve data from Parse - swift

Using the parse how to retrieve the data to the table view controller if multiple objects are present.
I tried using the query where receptionist equal to current user.
And I tried find objects in background and append it to an array.
But the problem is all the object values appending to the same array.

Read through the Parse IOS Developer's Guide. It has the information & explanations you need to do this.
http://parseplatform.org/docs/ios/guide/
Also, what you're asking really isn't too clear. Try to specify what specific issues you are having along with posting your actual code next time.

Related

How can I structure Firestore to store history of events that can easily be accessed?

I have been continuously changing my database structure and just can't find a good solution.
My database stores habits, each document is a different habit. The fields of the habits hold information on the habit, but where I am struggling is how to structure the completion/history.
Unlike a task, a habit is completed over and over again which means I need to store all that information and be able to query it easily for date ranges and such.
First
The first idea I had was a subcollection of documents that each held information such as the date, the completion status, etc.
Although this idea sounds good the problem was querying. I am using flutter and inside a StreamBuilder it proved difficult to access a sub-collection.
Second
My second idea was to use a document field in the habit. With this, I could have an array called completed, and the array would store a Map with the date, the status, etc.
With this idea, I made it the furthest, but where I struggle is changing the status of one field in the Map in the array.
Third
My third and most recent idea I haven't made much headway with yet but I was thinking I could use a nest Maps in the habits document field. A field called history would be equivalent to the map, then inside the Map, a date in string format would be equivalent to the Map that stores all the essential information.
This idea was great in a lot of ways, but querying the data by date range when the date is in a string format will inevitably be difficult.
Please let me know which structure is more ideal, or if there is a better way to do it. The language I am using is Flutter so I need to operate within the guidelines of the cloud_firestore package. Any help would be appreciated!

How can I retrieve all objects from a certain date and on using parse.com?

I am using parse.com. I need to get a list of strings that are stored in parse starting from the date that the user started using the app and on.
The only way I can think of is to get all the objects dates, and have an algorithm that tells me whether that particular object is more recent than the users start date, and only display those strings. I really don't want to do that, as it seems like more work than needed. Are there any other solutions out there?
In your 'PFQuery' for objects, use a constraint like [query whereKey:#"createdAt" isGreaterThanOrEqualTo:[PFUser currentUser].createdAt];.

Mongo pagination

I have a use case where I need to get list of Objects from mongo based off a query. But, to improve performance I am adding Pagination.
So, for first call I get list of say 10 Objects, in next I need 10 more. But I cannot use offset and pageSize directly because the first 10 objects displayed on the page may have been modified [ deleted ].
Solution is to find Object Id of last object passed and retrieve next 10 objects after that ObjectId.
Please help how to efficiently do it using Morphia mongo.
Using morphia you can do this by the following command.
datastore.find(YourClass.class).field(id).smallerThan(lastId).limit(10).order("-ts");
Since you are querying for retrieving the items after the last retrieved id, you won't be bothered to deal with deleted items.
One thing I have thought up of is that you will have the same problem as with using skip() here unless you intend to change how your interface works.
Using ranged queries like this demands that you use a different kind of interface since it is must harder to detect now exactly what page you are on and how many pages exist in the future, especially if you are doing this to avoid problems with conventional paging.
The default type of interface to arise from this type of paging is merely a infinitely scrolling page, think of YouTube video comments or Facebook wall feed or even Google+. There is no physical pagination or "pages", instead you have a get more button.
This is the type of interface you will need to use to get ranged paging working better.
As for the query #cubbuk gives a good example:
datastore.find(YourClass.class).field(id).smallerThan(lastId).limit(10).order("-ts");
Except it should be greaterThan(lastId) since you want to find everything above that last _id. I would also sort by _id unless you make your OjbectIds sometime before you insert a record, if this is the case then you can use a specific timestamp set on insert instead.

How to save / reload a custom array to a plist

I'm loading in data from an sqlite database, storing the values i load from there in the instance variables of a custom class, and then adding this class to a mutable array, which i'm then assigning to the instance variable of my view controller, for use in a tableview.
I would, though, like to save this array into a .plist file in the documents directory on the app's first run, so that i can retrieve the whole object from there on load, rather than pulling all 214 items from the database.
Is this approach a better option? if so, could someone please help provide me with some code that will allow me to save an array of my custom classes as a .plist file? I've come across a lot of sample code on the web, but none of it works correctly.
I'd like to:
Check for the existence of the my_data.plist file.
If it exists, read it in as the array.
If it doesn't, read the data from the sqlite db into an array.
save this data to a .plist so that it can be read in faster later.
Thanks guys, appreciate any help you can give me.
It will probably be faster to just get the values from your database on launch. There will almost definitely be more cost to parse a plist containing these values than to just get them all from the database, unless the query you have to use to get them from the database is really slow.
Note also that once you're saving these objects to a plist on disk, you're actually going to be hurting performance of your program because you'll be writing your objects to disk twice and reading them from disk twice. You'll also be introducing opportunities for discrepancies between the plist and the database in the event of a bug or a crash.
That said, the only way to prove this to yourself may be to implement and profile both options, and compare actual numbers. Check out #occulus's link, above, for instructions how to read and write a plist. To profile your app, try using Instruments
When I google for "nsarray writetofile custom object" (no quotes) and click on the first link in the results, I find a really useful page.
For the record, it's this:
http://www.cocoabuilder.com/archive/cocoa/240775-saving-nsarray-of-custom-objects.html

Whats more efficent Core Data Fetch or manipulate/create arrays?

I have a core data application and I would like to get results from the db, based on certain parameters. For example if I want to grab only the events that occured in the last week, and the events that occured in the last month. Is it better to do a fetch for the whole entity and then work with that result array, to create arrays out of that for each situation, or is it better to use predicates and make multiple fetches?
The answer depends on a lot of factors. I'd recommend perusing the documentation's description of the various store types. If you use the SQLite store type, for example, it's far more efficient to make proper use of date range predicates and fetch only those in the given range.
Conversely, say you use a non-standard attribute like searching for a substring in an encrypted string - you'll have to pull everything in, decrypt the strings, do your search, and note the matches.
On the far end of the spectrum, you have the binary store type, which means the whole thing will always be pulled into memory regardless of what kind of fetches you might do.
You'll need to describe your managed object model and the types of fetches you plan to do in order to get a more specific answer.