PlayerIO

The fastest way to build online games without breaking a sweat.

Objective-C Client Reference

Multiplayer  class documentationClass 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*)
allProperties
Get the names of all properties on this object
- (NSArray*)
allValues
Get all values from the properties of this object. Primitive properties (integers, floats, etc.) are wrapped in NSNumber
- (PIODatabaseArray*)
arrayForProperty:
Get the given DatabaseArray property
- (BOOL)
boolForProperty:
Get the given boolean property
- (BOOL)
boolForProperty:defaultValue:
Get the given boolean property, or the default if it doesn't exist.
- (void)
clear
Removes all properties on this object
- (BOOL)
containsProperty:
Returns true if the given property exists on this object
- (NSUInteger)
count
Returns the number of properties on this object
- (NSUInteger)
countByEnumeratingWithState:objects:count:
Fast enumeration over the properties in the object
- (NSData*)
dataForProperty:
Get the given byte array property
- (NSData*)
dataForProperty:defaultValue:
Get the given byte array property, or the default if it doesn't exist.
- (NSDate*)
dateForProperty:
Get the given Date property
- (NSDate*)
dateForProperty:defaultValue:
Get the given Date property, or the default if it doesn't exist.
- (double)
doubleForProperty:
Get the given double property
- (double)
doubleForProperty:defaultValue:
Get the given double property, or the default if it doesn't exist.
- (BOOL)
existsInDatabase
Returns true if this object has been persisted.
- (float)
floatForProperty:
Get the given float property
- (float)
floatForProperty:defaultValue:
Get the given float property, or the default if it doesn't exist.
- (int32_t)
intForProperty:
Get the given int property
- (int32_t)
intForProperty:defaultValue:
Get the given int property, or the default if it doesn't exist.
- (NSString*)
key
The key of the object.
- (NSEnumerator*)
keyEnumerator
Enumerator to move over keys used for properties in the object
- (int64_t)
longForProperty:
Get the given long property
- (int64_t)
longForProperty:defaultValue:
Get the given long property, or the default if it doesn't exist.
+ (PIODatabaseObject*)
object
Create a new autoreleased PIODatabaseObject
- (NSEnumerator*)
objectEnumerator
Enumerator to move over all properties in the object
- (PIODatabaseObject*)
objectForProperty:
Get the given DatabaseObject property
- (PIODatabaseObject*)
removeProperty:
Removes the given property from this object
- (void)
saveWithOptimisticLocking:fullOverwrite:successBlock:
Persist the object to the database asynchronously, using optimistic locking and full overwrite if specified.
- (void)
saveWithOptimisticLocking:fullOverwrite:successBlock:errorBlock:
Persist the object to the database asynchronously, using optimistic locking and full overwrite if specified.
- (void)
saveWithOptimisticLocking:successBlock:
Persist the object to the database asynchronously, using optimistic locking if specified.
- (void)
saveWithOptimisticLocking:successBlock:errorBlock:
Persist the object to the database asynchronously, using optimistic locking if specified.
- (void)
saveWithSuccessBlock:
Persist the object to the database asynchronously.
- (void)
saveWithSuccessBlock:errorBlock:
Persist the object to the database asynchronously.
- (PIODatabaseObject*)
setArray:forProperty:
Set the specified property to the given DatabaseArray value
- (PIODatabaseObject*)
setBool:forProperty:
Set the specified property to the given boolean value
- (PIODatabaseObject*)
setData:forProperty:
Set the specified property to the given bye array value
- (PIODatabaseObject*)
setDate:forProperty:
Set the specified property to the given Date value
- (PIODatabaseObject*)
setDouble:forProperty:
Set the specified property to the given double value
- (PIODatabaseObject*)
setFloat:forProperty:
Set the specified property to the given float value
- (PIODatabaseObject*)
setInt:forProperty:
Set the specified property to the given int value
- (PIODatabaseObject*)
setLong:forProperty:
Set the specified property to the given long value
- (PIODatabaseObject*)
setObject:forProperty:
Set the specified property to the given DatabaseObject value
- (PIODatabaseObject*)
setString:forProperty:
Set the specified property to the given string value
- (PIODatabaseObject*)
setUInt:forProperty:
Set the specified property to the given uint value
- (NSString*)
stringForProperty:
Get the given String property
- (NSString*)
stringForProperty:defaultValue:
Get the given String property, or the default if it doesn't exist.
- (NSString*)
table
The name of the BigDB table this object belongs to
- (uint32_t)
uintForProperty:
Get the given uint property
- (uint32_t)
uintForProperty:defaultValue:
Get the given uint property, or the default if it doesn't exist.
- (id)
valueForProperty:
Get the given property as an object. Primitive properties (integers, floats, etc.) are wrapped in NSNumber

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
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded.
BOOL fullOverwrite
Will completely overwrite the database object in BigDB with the properties in this instance, instead of just sending the changed properties to the server.
void(^)(void) successBlock
A block that will be called if the call succeeds

saveWithOptimisticLocking:fullOverwrite:successBlock:errorBlock:

Persist the object to the database asynchronously, using optimistic locking and full overwrite if specified.

Arguments

BOOL useOptimisticLocks
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded.
BOOL fullOverwrite
Will completely overwrite the database object in BigDB with the properties in this instance, instead of just sending the changed properties to the server.
void(^)(void) successBlock
A block that will be called if the call succeeds
void(^)(PIOError*error) errorBlock
A block that will be called if the call fails, with an error object describing what went wrong.

saveWithOptimisticLocking:successBlock:

Persist the object to the database asynchronously, using optimistic locking if specified.

Arguments

BOOL useOptimisticLocks
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded.
void(^)(void) successBlock
A block that will be called if the call succeeds

saveWithOptimisticLocking:successBlock:errorBlock:

Persist the object to the database asynchronously, using optimistic locking if specified.

Arguments

BOOL useOptimisticLocks
If true, the save will only be completed if the database object has not changed in BigDB since this instance was loaded.
void(^)(void) successBlock
A block that will be called if the call succeeds
void(^)(PIOError*error) errorBlock
A block that will be called if the call fails, with an error object describing what went wrong.

saveWithSuccessBlock:

Persist the object to the database asynchronously.

Arguments

void(^)(void) successBlock
A block that will be called if the call succeeds

saveWithSuccessBlock:errorBlock:

Persist the object to the database asynchronously.

Arguments

void(^)(void) successBlock
A block that will be called if the call succeeds
void(^)(PIOError*error) errorBlock
A block that will be called if the call fails, with an error object describing what went wrong.

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