Vous êtes sur la page 1sur 4

Introduction

The platform provides a complete backend solution for the mobile application.

Apps
you create an App for each of your mobile applications. Each App has its own
application id and client key that you apply to your SDK install. Your account on Parse
can accommodate multiple Apps. This is useful even if you have one application, since
you can deploy different versions for test and production.

Objects
The PFObject
Storing data on Parse is built around the PFObject. Each PFObject contains key-value
pairs of JSON-compatible data. This data is schemaless, which means that you don't
need to specify ahead of time what keys exist on each PFObject. You simply set
whatever key-value pairs you want, and our backend will store it.
Keys must be alphanumeric strings. Values can be strings, numbers, booleans, or even
arrays and dictionaries - anything that can be JSON-encoded.

Saving Objects
The interface is similar to a NSMutableDictionary
After the code runs, you will probably be wondering if anything really happened. To
make sure the data was saved, you can look at the Data Browser in your app on Parse.

Retrieving Objects
If you have the objectId, you can retrieve the wholePFObject using a PFQuery.
This is an asynchronous method, with variations for using either blocks or callback
methods:

The Local Datastore


Parse also lets you store objects in a local datastore on the device itself. You can use
this for data that doesn't need to be saved to the cloud, but this is especially useful for
temporarily storing data so that it can be synced later. To enable the datastore,
add libsqlite3.dylib and call [Parse enableLocalDatastore] in
your AppDelegate application:didFinishLaunchWithOptions: before calling
[Parse setApplicationId:clientKey:]. Once the local datastore is enabled, you
can store an object by pinning it.

Retrieving Objects from the Local Datastore


Storing an object is only useful if you can get it back out. To get the data for a specific
object, you can use a PFQuery just like you would while on the network, but using
the fromLocalDatastore method to tell it where to get the data.

Saving Objects Offline


Most save functions execute immediately, and inform your app when the save is
complete. If you don't need to know when the save has finished, you can
use saveEventually instead. The advantage is that if the user currently doesn't have a
network connection,saveEventually will store the update on the device until a network
connection is re-established. If your app is closed before the connection is back, Parse
will
try
again
the
next
time
the
app
is
opened.
All
calls

to saveEventually (and deleteEventually) are executed in the order they are called,
so it is safe to call saveEventually on an object multiple times.

Updating Objects
Updating an object is simple. Just set some new data on it and call one of the save
methods. Assuming you have saved the object and have the objectId, you can retrieve
the PFObject using a PFQuery and update its data

Counters
The above example contains a common use case. The "score" field is a counter that
we'll need to continually update with the player's latest score. Using the above method
works but it's cumbersome and can lead to problems if you have multiple clients trying
to update the same counter.

Arrays
To help with storing array data, there are three operations that can be used to atomically
change an array field:

addObject:forKey: and addObjectsFromArray:forKey: append the given

objects to the end of an array field.


addUniqueObject:forKey: and addUniqueObjectsFromArray:forKey: add only
the given objects which aren't already contained in an array field to that field.
The position of the insert is not guaranteed.
removeObject:forKey: and removeObjectsInArray:forKey: remove all
instances of each given object from an array field.

Deleting Objects
To delete an object use: deleteInBackground

If you want to run a callback when the delete is confirmed, you can use
the deleteInBackgroundWithBlock: ordeleteInBackgroundWithTarget:selector
methods. If you want to block the calling thread, you can use the delete method.

Relational Data
Objects can have relationships with other objects. To model this behavior,
any PFObject can be used as a value in other PFObjects. Internally, the Parse
framework will store the referred-to object in just one place, to maintain consistency.

Data Types
Parse also supports NSDate, NSData, and NSNull.
You can nest NSDictionary and NSArray objects to store more structured data within a
single PFObject.
Some examples:

Vous aimerez peut-être aussi