Objective-C Client Reference
Class PIODatabaseObject
Language: Objective-C
This class represents a BigDB Database Object that has a key and a collection of named properties.
There are methods for setting, getting, and removing properties, and changes to the object can be persisted to BigDB with the -save: method.
Database objects are very similar to JSON objects and are most easily visualized as such. For example, we can visualize a car object like this:
If we then want to create this object in BigDB, we would have to do this:
To make it easier to work with nested objects, you can reference them directly by separating the property names with a dot. Using this, we can set the stats properties of the car like this instead:
When you want to read properties from a database object, you have to call the corresponding get method indicating the type of the property.
BigDB doesn't enforce anything on your objects. Two objects in the same table do not need to have the same properties set, and do not need to have the same type on the same property. If you try to get a property that is missing, or if you are using a get method of the wrong type, you will get an exception.
One way of avoiding this is to first check the object if a certain property exists before reading this. You can do this with the Contains method.
Another way of avoiding errors is to specify a default value when calling a get method. If the object doesn't contain the property, the method will return your default value instead.
You can also easily remove properties from your object with the Remove method.
Finally, to persist any changes you've made to an object you can call the Save method. Note that you can only call Save on an object that exist in the database. This means that the first time you save an object you have to call the CreateObject method, but all subsequent times you can call the Save method. There is also a method called existsInDatabase that you can use to check if it has been created or not.
The Save method is asynchronous just like the CreateObject method in PlayerIO.BigDB, and you can specify a callback if you wish to do something when the object actually has been saved.
Methods | |||
---|---|---|---|
- (NSArray*) |
|
||
- (NSArray*) |
|
||
- (PIODatabaseArray*) |
|
||
- (BOOL) |
|
||
- (BOOL) |
|
||
- (void) |
|
||
- (BOOL) |
|
||
- (NSUInteger) |
|
||
- (NSUInteger) |
|
||
- (NSData*) |
|
||
- (NSData*) |
|
||
- (NSDate*) |
|
||
- (NSDate*) |
|
||
- (double) |
|
||
- (double) |
|
||
- (BOOL) |
|
||
- (float) |
|
||
- (float) |
|
||
- (int32_t) |
|
||
- (int32_t) |
|
||
- (NSString*) |
|
||
- (NSEnumerator*) |
|
||
- (int64_t) |
|
||
- (int64_t) |
|
||
+ (PIODatabaseObject*) |
|
||
- (NSEnumerator*) |
|
||
- (PIODatabaseObject*) |
|
||
- (PIODatabaseObject*) |
|
||
- (void) |
|
||
- (void) |
|
||
- (void) |
|
||
- (void) |
|
||
- (void) |
|
||
- (void) |
|
||
- (PIODatabaseObject*) |
|
||
- (PIODatabaseObject*) |
|
||
- (PIODatabaseObject*) |
|
||
- (PIODatabaseObject*) |
|
||
- (PIODatabaseObject*) |
|
||
- (PIODatabaseObject*) |
|
||
- (PIODatabaseObject*) |
|
||
- (PIODatabaseObject*) |
|
||
- (PIODatabaseObject*) |
|
||
- (PIODatabaseObject*) |
|
||
- (PIODatabaseObject*) |
|
||
- (NSString*) |
|
||
- (NSString*) |
|
||
- (NSString*) |
|
||
- (uint32_t) |
|
||
- (uint32_t) |
|
||
- (id) |
|
allProperties
Get the names of all properties on this object
Return Value
NSArray* | |
allValues
Get all values from the properties of this object. Primitive properties (integers, floats, etc.) are wrapped in NSNumber
Return Value
NSArray* | |
arrayForProperty:
Get the given DatabaseArray property
Arguments
NSString* | propertyExpression |
Return Value
PIODatabaseArray* | |
boolForProperty:
Get the given boolean property
Arguments
NSString* | propertyExpression |
Return Value
BOOL | |
boolForProperty:defaultValue:
Get the given boolean property, or the default if it doesn't exist.
Arguments
NSString* | propertyExpression |
BOOL | defaultValue |
Return Value
BOOL | |
clear
Removes all properties on this object
containsProperty:
Returns true if the given property exists on this object
Arguments
NSString* | propertyExpression |
Return Value
BOOL | |
count
Returns the number of properties on this object
Return Value
NSUInteger | |
countByEnumeratingWithState:objects:count:
Fast enumeration over the properties in the object
Arguments
NSFastEnumerationState* | state |
id* | stackbuf |
NSUInteger | len |
Return Value
NSUInteger | |
dataForProperty:
Get the given byte array property
Arguments
NSString* | propertyExpression |
Return Value
NSData* | |
dataForProperty:defaultValue:
Get the given byte array property, or the default if it doesn't exist.
Arguments
NSString* | propertyExpression |
NSData* | defaultValue |
Return Value
NSData* | |
dateForProperty:
Get the given Date property
Arguments
NSString* | propertyExpression |
Return Value
NSDate* | |
dateForProperty:defaultValue:
Get the given Date property, or the default if it doesn't exist.
Arguments
NSString* | propertyExpression |
NSDate* | defaultValue |
Return Value
NSDate* | |
doubleForProperty:
Get the given double property
Arguments
NSString* | propertyExpression |
Return Value
double | |
doubleForProperty:defaultValue:
Get the given double property, or the default if it doesn't exist.
Arguments
NSString* | propertyExpression |
double | defaultValue |
Return Value
double | |
existsInDatabase
Returns true if this object has been persisted.
Return Value
BOOL | |
floatForProperty:
Get the given float property
Arguments
NSString* | propertyExpression |
Return Value
float | |
floatForProperty:defaultValue:
Get the given float property, or the default if it doesn't exist.
Arguments
NSString* | propertyExpression |
float | defaultValue |
Return Value
float | |
intForProperty:
Get the given int property
Arguments
NSString* | propertyExpression |
Return Value
int32_t | |
intForProperty:defaultValue:
Get the given int property, or the default if it doesn't exist.
Arguments
NSString* | propertyExpression |
int32_t | defaultValue |
Return Value
int32_t | |
key
The key of the object.
Return Value
NSString* | |
keyEnumerator
Enumerator to move over keys used for properties in the object
Return Value
NSEnumerator* | |
longForProperty:
Get the given long property
Arguments
NSString* | propertyExpression |
Return Value
int64_t | |
longForProperty:defaultValue:
Get the given long property, or the default if it doesn't exist.
Arguments
NSString* | propertyExpression |
int64_t | defaultValue |
Return Value
int64_t | |
object
Create a new autoreleased PIODatabaseObject
Return Value
PIODatabaseObject* | |
objectEnumerator
Enumerator to move over all properties in the object
Return Value
NSEnumerator* | |
objectForProperty:
Get the given DatabaseObject property
Arguments
NSString* | propertyExpression |
Return Value
PIODatabaseObject* | |
removeProperty:
Removes the given property from this object
Arguments
NSString* | propertyExpression |
Return Value
PIODatabaseObject* | |
saveWithOptimisticLocking:fullOverwrite:successBlock:
Persist the object to the database asynchronously, using optimistic locking and full overwrite if specified.
Arguments
BOOL | useOptimisticLocks |
BOOL | fullOverwrite |
void(^)(void) | successBlock |
saveWithOptimisticLocking:fullOverwrite:successBlock:errorBlock:
Persist the object to the database asynchronously, using optimistic locking and full overwrite if specified.
Arguments
BOOL | useOptimisticLocks |
BOOL | fullOverwrite |
void(^)(void) | successBlock |
void(^)(PIOError*error) | errorBlock |
saveWithOptimisticLocking:successBlock:
Persist the object to the database asynchronously, using optimistic locking if specified.
Arguments
BOOL | useOptimisticLocks |
void(^)(void) | successBlock |
saveWithOptimisticLocking:successBlock:errorBlock:
Persist the object to the database asynchronously, using optimistic locking if specified.
Arguments
BOOL | useOptimisticLocks |
void(^)(void) | successBlock |
void(^)(PIOError*error) | errorBlock |
saveWithSuccessBlock:
Persist the object to the database asynchronously.
Arguments
void(^)(void) | successBlock |
saveWithSuccessBlock:errorBlock:
Persist the object to the database asynchronously.
Arguments
void(^)(void) | successBlock |
void(^)(PIOError*error) | errorBlock |
setArray:forProperty:
Set the specified property to the given DatabaseArray value
Arguments
PIODatabaseArray* | value |
NSString* | propertyExpression |
Return Value
PIODatabaseObject* | |
setBool:forProperty:
Set the specified property to the given boolean value
Arguments
BOOL | value |
NSString* | propertyExpression |
Return Value
PIODatabaseObject* | |
setData:forProperty:
Set the specified property to the given bye array value
Arguments
NSData* | value |
NSString* | propertyExpression |
Return Value
PIODatabaseObject* | |
setDate:forProperty:
Set the specified property to the given Date value
Arguments
NSDate* | value |
NSString* | propertyExpression |
Return Value
PIODatabaseObject* | |
setDouble:forProperty:
Set the specified property to the given double value
Arguments
double | value |
NSString* | propertyExpression |
Return Value
PIODatabaseObject* | |
setFloat:forProperty:
Set the specified property to the given float value
Arguments
float | value |
NSString* | propertyExpression |
Return Value
PIODatabaseObject* | |
setInt:forProperty:
Set the specified property to the given int value
Arguments
int32_t | value |
NSString* | propertyExpression |
Return Value
PIODatabaseObject* | |
setLong:forProperty:
Set the specified property to the given long value
Arguments
int64_t | value |
NSString* | propertyExpression |
Return Value
PIODatabaseObject* | |
setObject:forProperty:
Set the specified property to the given DatabaseObject value
Arguments
PIODatabaseObject* | value |
NSString* | propertyExpression |
Return Value
PIODatabaseObject* | |
setString:forProperty:
Set the specified property to the given string value
Arguments
NSString* | value |
NSString* | propertyExpression |
Return Value
PIODatabaseObject* | |
setUInt:forProperty:
Set the specified property to the given uint value
Arguments
uint32_t | value |
NSString* | propertyExpression |
Return Value
PIODatabaseObject* | |
stringForProperty:
Get the given String property
Arguments
NSString* | propertyExpression |
Return Value
NSString* | |
stringForProperty:defaultValue:
Get the given String property, or the default if it doesn't exist.
Arguments
NSString* | propertyExpression |
NSString* | defaultValue |
Return Value
NSString* | |
table
The name of the BigDB table this object belongs to
Return Value
NSString* | |
uintForProperty:
Get the given uint property
Arguments
NSString* | propertyExpression |
Return Value
uint32_t | |
uintForProperty:defaultValue:
Get the given uint property, or the default if it doesn't exist.
Arguments
NSString* | propertyExpression |
uint | defaultValue |
Return Value
uint32_t | |
valueForProperty:
Get the given property as an object. Primitive properties (integers, floats, etc.) are wrapped in NSNumber
Arguments
NSString* | propertyExpression |
Return Value
id | |