AVObject Class Reference

Inherits from NSObject
Conforms to NSCoding
Declared in AVObject.h

Overview

An object that is a local representation of data persisted to the LeanCloud. This is the main class that is used to interact with objects in your app.

Subclassing Notes

Developers can subclass AVObject for a more native object-oriented class structure. Strongly-typed subclasses of AVObject must conform to the AVSubclassing protocol and must call registerSubclass to be returned by AVQuery and other AVObject factories. All methods in AVSubclassing except for [AVSubclassing parseClassName] are already implemented in the AVObject(Subclass) category. Inculding AVObject+Subclass.h in your implementation file provides these implementations automatically.

Subclasses support simpler initializers, query syntax, and dynamic synthesizers.

Other Methods

+ objectWithObjectId:

Creates a reference to an existing AVObject with an object ID.

+ (instancetype)objectWithObjectId:(NSString *)objectId

Parameters

objectId

The object ID.

Return Value

An object with the given object ID.

Discussion

Creates a reference to an existing AVObject with an object ID.

Calling isDataAvailable on this object will return NO until fetchIfNeeded or refresh has been called.

Declared In

AVObject.h

Creating a AVObject

+ objectWithClassName:

Creates a new AVObject with a class name.

+ (instancetype)objectWithClassName:(NSString *)className

Parameters

className

A class name can be any alphanumeric string that begins with a letter. It represents an object in your app, like a User of a Document.

Return Value

the object that is instantiated with the given class name.

Discussion

Creates a new AVObject with a class name.

Declared In

AVObject.h

+ objectWithClassName:objectId:

Creates a reference to an existing AVObject for use in creating associations between AVObjects.

+ (instancetype)objectWithClassName:(NSString *)className objectId:(NSString *)objectId

Parameters

className

The object’s class name.

objectId

The object ID for the referenced object.

Return Value

An object with the given class name and object ID.

Discussion

Creates a reference to an existing AVObject for use in creating associations between AVObjects.

Calling isDataAvailable on this object will return NO until fetchIfNeeded or refresh has been called.

Declared In

AVObject.h

+ objectWithClassName:dictionary:

Creates a new AVObject with a class name, initialized with data constructed from the specified set of objects and keys.

+ (instancetype)objectWithClassName:(NSString *)className dictionary:(NSDictionary *)dictionary

Parameters

className

The object’s class.

dictionary

An NSDictionary of keys and objects to set on the new AVObject.

Return Value

A AVObject with the given class name and set with the given data.

Discussion

Creates a new AVObject with a class name, initialized with data constructed from the specified set of objects and keys.

Declared In

AVObject.h

– initWithClassName:

Initializes a new AVObject with a class name.

- (instancetype)initWithClassName:(NSString *)newClassName

Parameters

newClassName

A class name can be any alphanumeric string that begins with a letter. It represents an object in your app, like a User or a Document.

Return Value

the object that is instantiated with the given class name.

Discussion

Initializes a new AVObject with a class name.

Declared In

AVObject.h

+ setConvertingNullToNil:

If YES, Null value will be converted to nil when getting object for key. Because [NSNull null] is truthy value in Objective-C. Default is YES and suggested.

+ (void)setConvertingNullToNil:(BOOL)yesOrNo

Parameters

yesOrNo

default is YES.

Discussion

If YES, Null value will be converted to nil when getting object for key. Because [NSNull null] is truthy value in Objective-C. Default is YES and suggested.

Warning: It takes effects only when getting object for key. You can still use Null in setObject:forKey.

Declared In

AVObject.h

Managing Object Properties

  objectId

The id of the object.

@property (nonatomic, copy, readonly, nullable) NSString *objectId

Discussion

The id of the object.

Declared In

AVObject.h

  updatedAt

When the object was last updated.

@property (nonatomic, strong, readonly, nullable) NSDate *updatedAt

Discussion

When the object was last updated.

Declared In

AVObject.h

  createdAt

When the object was created.

@property (nonatomic, strong, readonly, nullable) NSDate *createdAt

Discussion

When the object was created.

Declared In

AVObject.h

  className

The class name of the object.

@property (nonatomic, copy, readonly) NSString *className

Discussion

The class name of the object.

Declared In

AVObject.h

  ACL

The ACL for this object.

@property (nonatomic, strong, nullable) AVACL *ACL

Discussion

The ACL for this object.

Declared In

AVObject.h

– allKeys

Returns an array of the keys contained in this object. This does not include createdAt, updatedAt, authData, or objectId. It does include things like username and ACL.

- (NSArray *)allKeys

Discussion

Returns an array of the keys contained in this object. This does not include createdAt, updatedAt, authData, or objectId. It does include things like username and ACL.

Declared In

AVObject.h

– objectForKey:

Returns the object associated with a given key.

- (nullable id)objectForKey:(NSString *)key

Parameters

key

The key that the object is associated with.

Return Value

The value associated with the given key, or nil if no value is associated with key.

Discussion

Returns the object associated with a given key.

Declared In

AVObject.h

– setObject:forKey:

Sets the object associated with a given key.

- (void)setObject:(nullable id)object forKey:(NSString *)key

Parameters

object

The object.

key

The key.

Discussion

Sets the object associated with a given key.

Declared In

AVObject.h

– removeObjectForKey:

Unsets a key on the object.

- (void)removeObjectForKey:(NSString *)key

Parameters

key

The key.

Discussion

Unsets a key on the object.

Declared In

AVObject.h

– objectForKeyedSubscript:

  • In LLVM 4.0 (XCode 4.5) or higher allows myAVObject[key].
- (nullable id)objectForKeyedSubscript:(NSString *)key

Parameters

key

The key.

Discussion

  • In LLVM 4.0 (XCode 4.5) or higher allows myAVObject[key].

Declared In

AVObject.h

– setObject:forKeyedSubscript:

  • In LLVM 4.0 (XCode 4.5) or higher allows myObject[key] = value
- (void)setObject:(nullable id)object forKeyedSubscript:(NSString *)key

Parameters

object

The object.

key

The key.

Discussion

  • In LLVM 4.0 (XCode 4.5) or higher allows myObject[key] = value

Declared In

AVObject.h

– relationForKey:

Returns the relation object associated with the given key

- (AVRelation *)relationForKey:(NSString *)key

Parameters

key

The key that the relation is associated with.

Discussion

Returns the relation object associated with the given key

Declared In

AVObject.h

– addObject:forKey:

Adds an object to the end of the array associated with a given key.

- (void)addObject:(id)object forKey:(NSString *)key

Parameters

object

The object to add.

key

The key.

Discussion

Adds an object to the end of the array associated with a given key.

Declared In

AVObject.h

– addObjectsFromArray:forKey:

Adds the objects contained in another array to the end of the array associated with a given key.

- (void)addObjectsFromArray:(NSArray *)objects forKey:(NSString *)key

Parameters

objects

The array of objects to add.

key

The key.

Discussion

Adds the objects contained in another array to the end of the array associated with a given key.

Declared In

AVObject.h

– addUniqueObject:forKey:

Adds an object to the array associated with a given key, only if it is not already present in the array. The position of the insert is not guaranteed.

- (void)addUniqueObject:(id)object forKey:(NSString *)key

Parameters

object

The object to add.

key

The key.

Discussion

Adds an object to the array associated with a given key, only if it is not already present in the array. The position of the insert is not guaranteed.

Declared In

AVObject.h

– addUniqueObjectsFromArray:forKey:

Adds the objects contained in another array to the array associated with a given key, only adding elements which are not already present in the array. The position of the insert is not guaranteed.

- (void)addUniqueObjectsFromArray:(NSArray *)objects forKey:(NSString *)key

Parameters

objects

The array of objects to add.

key

The key.

Discussion

Adds the objects contained in another array to the array associated with a given key, only adding elements which are not already present in the array. The position of the insert is not guaranteed.

Declared In

AVObject.h

– removeObject:forKey:

Removes all occurrences of an object from the array associated with a given key.

- (void)removeObject:(id)object forKey:(NSString *)key

Parameters

object

The object to remove.

key

The key.

Discussion

Removes all occurrences of an object from the array associated with a given key.

Declared In

AVObject.h

– removeObjectsInArray:forKey:

Removes all occurrences of the objects contained in another array from the array associated with a given key.

- (void)removeObjectsInArray:(NSArray *)objects forKey:(NSString *)key

Parameters

objects

The array of objects to remove.

key

The key.

Discussion

Removes all occurrences of the objects contained in another array from the array associated with a given key.

Declared In

AVObject.h

– incrementKey:

Increments the given key by 1.

- (void)incrementKey:(NSString *)key

Parameters

key

The key.

Discussion

Increments the given key by 1.

Declared In

AVObject.h

– incrementKey:byAmount:

Increments the given key by a number.

- (void)incrementKey:(NSString *)key byAmount:(NSNumber *)amount

Parameters

key

The key.

amount

The amount to increment.

Discussion

Increments the given key by a number.

Declared In

AVObject.h

Saving an Object to LeanCloud

– save

Saves the AVObject.

- (BOOL)save

Return Value

whether the save succeeded.

Discussion

Saves the AVObject.

Declared In

AVObject.h

– save:

Saves the AVObject and sets an error if it occurs.

- (BOOL)save:(NSError **)error

Parameters

error

Pointer to an NSError that will be set if necessary.

Return Value

whether the save succeeded.

Discussion

Saves the AVObject and sets an error if it occurs.

Declared In

AVObject.h

– saveAndThrowsWithError:

An alias of [AVObject save:] methods that supports Swift exception. @seealso [AVObject save:]

- (BOOL)saveAndThrowsWithError:(NSError **)error

Discussion

An alias of [AVObject save:] methods that supports Swift exception. @seealso [AVObject save:]

Declared In

AVObject.h

– saveWithOption:error:

Saves the AVObject with option and sets an error if it occurs.

- (BOOL)saveWithOption:(nullable AVSaveOption *)option error:(NSError **)error

Parameters

option

Option for current save.

error

A pointer to an NSError that will be set if necessary.

Return Value

Whether the save succeeded.

Discussion

Saves the AVObject with option and sets an error if it occurs.

Declared In

AVObject.h

– saveWithOption:eventually:error:

Saves the AVObject with option and sets an error if it occurs.

- (BOOL)saveWithOption:(nullable AVSaveOption *)option eventually:(BOOL)eventually error:(NSError **)error

Parameters

option

Option for current save.

eventually

Whether save in eventually or not.

error

A pointer to an NSError that will be set if necessary.

Return Value

Whether the save succeeded.

Discussion

Saves the AVObject with option and sets an error if it occurs.

Note: If eventually is specified to YES, request will be stored locally in an on-disk cache until it can be delivered to server.

Declared In

AVObject.h

– saveInBackground

Saves the AVObject asynchronously.

- (void)saveInBackground

Discussion

Saves the AVObject asynchronously.

Declared In

AVObject.h

– saveInBackgroundWithBlock:

Saves the AVObject asynchronously and executes the given callback block.

- (void)saveInBackgroundWithBlock:(AVBooleanResultBlock)block

Parameters

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Discussion

Saves the AVObject asynchronously and executes the given callback block.

Declared In

AVObject.h

– saveInBackgroundWithOption:block:

Saves the AVObject with option asynchronously and executes the given callback block.

- (void)saveInBackgroundWithOption:(nullable AVSaveOption *)option block:(AVBooleanResultBlock)block

Parameters

option

Option for current save.

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Discussion

Saves the AVObject with option asynchronously and executes the given callback block.

Declared In

AVObject.h

– saveInBackgroundWithOption:eventually:block:

Saves the AVObject with option asynchronously and executes the given callback block.

- (void)saveInBackgroundWithOption:(nullable AVSaveOption *)option eventually:(BOOL)eventually block:(AVBooleanResultBlock)block

Parameters

option

Option for current save.

eventually

Whether save in eventually or not.

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Discussion

Saves the AVObject with option asynchronously and executes the given callback block.

Declared In

AVObject.h

– saveInBackgroundWithTarget:selector:

Saves the AVObject asynchronously and calls the given callback.

- (void)saveInBackgroundWithTarget:(id)target selector:(SEL)selector

Parameters

target

The object to call selector on.

selector

The selector to call. It should have the following signature: (void)callbackWithResult:(NSNumber )result error:(NSError )error. error will be nil on success and set if there was an error. [result boolValue] will tell you whether the call succeeded or not.

Discussion

Saves the AVObject asynchronously and calls the given callback.

Declared In

AVObject.h

– saveInBackgroundWithOption:target:selector:

Saves the AVObject with option asynchronously and calls the given callback.

- (void)saveInBackgroundWithOption:(nullable AVSaveOption *)option target:(id)target selector:(SEL)selector

Parameters

option

Option for current save.

target

The object to call selector on.

selector

The selector to call. It should have the following signature: (void)callbackWithResult:(NSNumber )result error:(NSError )error. error will be nil on success and set if there was an error. [result boolValue] will tell you whether the call succeeded or not.

Discussion

Saves the AVObject with option asynchronously and calls the given callback.

Declared In

AVObject.h

– saveEventually

- (void)saveEventually

Declared In

AVObject.h

– saveEventually:

Saves this object to the server at some unspecified time in the future, even if LeanCloud is currently inaccessible. Use this when you may not have a solid network connection, and don’t need to know when the save completes. If there is some problem with the object such that it can’t be saved, it will be silently discarded. If the save completes successfully while the object is still in memory, then callback will be called.

- (void)saveEventually:(AVBooleanResultBlock)callback

Parameters

callback

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Discussion

Saves this object to the server at some unspecified time in the future, even if LeanCloud is currently inaccessible. Use this when you may not have a solid network connection, and don’t need to know when the save completes. If there is some problem with the object such that it can’t be saved, it will be silently discarded. If the save completes successfully while the object is still in memory, then callback will be called.

Objects saved with this method will be stored locally in an on-disk cache until they can be delivered to LeanCloud. They will be sent immediately if possible. Otherwise, they will be sent the next time a network connection is available. Objects saved this way will persist even after the app is closed, in which case they will be sent the next time the app is opened. If more than 10MB of data is waiting to be sent, subsequent calls to saveEventually will cause old saves to be silently discarded until the connection can be re-established, and the queued objects can be saved.

Declared In

AVObject.h

Saving Many Objects to LeanCloud

+ saveAll:

Saves a collection of objects all at once.

+ (BOOL)saveAll:(NSArray *)objects

Parameters

objects

The array of objects to save.

Return Value

whether the save succeeded.

Discussion

Saves a collection of objects all at once.

Declared In

AVObject.h

+ saveAll:error:

Saves a collection of objects all at once and sets an error if necessary.

+ (BOOL)saveAll:(NSArray *)objects error:(NSError **)error

Parameters

objects

The array of objects to save.

error

Pointer to an NSError that will be set if necessary.

Return Value

whether the save succeeded.

Discussion

Saves a collection of objects all at once and sets an error if necessary.

Declared In

AVObject.h

+ saveAllInBackground:

Saves a collection of objects all at once asynchronously.

+ (void)saveAllInBackground:(NSArray *)objects

Parameters

objects

The array of objects to save.

Discussion

Saves a collection of objects all at once asynchronously.

Declared In

AVObject.h

+ saveAllInBackground:block:

Saves a collection of objects all at once asynchronously and the block when done.

+ (void)saveAllInBackground:(NSArray *)objects block:(AVBooleanResultBlock)block

Parameters

objects

The array of objects to save.

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Discussion

Saves a collection of objects all at once asynchronously and the block when done.

Declared In

AVObject.h

+ saveAllInBackground:target:selector:

Saves a collection of objects all at once asynchronously and calls a callback when done.

+ (void)saveAllInBackground:(NSArray *)objects target:(id)target selector:(SEL)selector

Parameters

objects

The array of objects to save.

target

The object to call selector on.

selector

The selector to call. It should have the following signature: (void)callbackWithError:(NSError *)error. error will be nil on success and set if there was an error.

Discussion

Saves a collection of objects all at once asynchronously and calls a callback when done.

Declared In

AVObject.h

Getting an Object from LeanCloud

– isDataAvailable

Gets whether the AVObject has been fetched.

- (BOOL)isDataAvailable

Return Value

YES if the AVObject is new or has been fetched or refreshed. NO otherwise.

Discussion

Gets whether the AVObject has been fetched.

Declared In

AVObject.h

– refresh

Refreshes the AVObject with the current data from the server.

- (void)refresh

Discussion

Refreshes the AVObject with the current data from the server.

Declared In

AVObject.h

– refreshWithKeys:

Refreshes the AVObject with the current data from the server.

- (void)refreshWithKeys:(NSArray *)keys

Parameters

keys

Pointer to an NSArray that contains objects specified by the keys want to fetch.

Discussion

Refreshes the AVObject with the current data from the server.

Declared In

AVObject.h

– refresh:

Refreshes the AVObject with the current data from the server and sets an error if it occurs.

- (BOOL)refresh:(NSError **)error

Parameters

error

Pointer to an NSError that will be set if necessary.

Return Value

success or not

Discussion

Refreshes the AVObject with the current data from the server and sets an error if it occurs.

Declared In

AVObject.h

– refreshAndThrowsWithError:

An alias of [AVObject refresh:] methods that supports Swift exception. @seealso [AVObject refresh:]

- (BOOL)refreshAndThrowsWithError:(NSError **)error

Discussion

An alias of [AVObject refresh:] methods that supports Swift exception. @seealso [AVObject refresh:]

Declared In

AVObject.h

– refreshInBackgroundWithBlock:

Refreshes the AVObject asynchronously and executes the given callback block.

- (void)refreshInBackgroundWithBlock:(AVObjectResultBlock)block

Parameters

block

The block to execute. The block should have the following argument signature: (AVObject object, NSError error)

Discussion

Refreshes the AVObject asynchronously and executes the given callback block.

Declared In

AVObject.h

– refreshInBackgroundWithKeys:block:

Refreshes the AVObject with the current data from the server.

- (void)refreshInBackgroundWithKeys:(NSArray *)keys block:(AVObjectResultBlock)block

Parameters

keys

Pointer to an NSArray that contains objects specified by the keys want to fetch.

block

The block to execute. The block should have the following argument signature: (AVObject object, NSError error)

Discussion

Refreshes the AVObject with the current data from the server.

Declared In

AVObject.h

– refreshInBackgroundWithTarget:selector:

Refreshes the AVObject asynchronously and calls the given callback.

- (void)refreshInBackgroundWithTarget:(id)target selector:(SEL)selector

Parameters

target

The target on which the selector will be called.

selector

The selector to call. It should have the following signature: (void)callbackWithResult:(AVObject )refreshedObject error:(NSError )error. error will be nil on success and set if there was an error. refreshedObject will be the AVObject with the refreshed data.

Discussion

Refreshes the AVObject asynchronously and calls the given callback.

Declared In

AVObject.h

– fetch

Fetches the AVObject with the current data from the server.

- (BOOL)fetch

Discussion

Fetches the AVObject with the current data from the server.

Declared In

AVObject.h

– fetch:

Fetches the AVObject with the current data from the server and sets an error if it occurs.

- (BOOL)fetch:(NSError **)error

Parameters

error

Pointer to an NSError that will be set if necessary.

Return Value

success or not

Discussion

Fetches the AVObject with the current data from the server and sets an error if it occurs.

Declared In

AVObject.h

– fetchAndThrowsWithError:

An alias of [AVObject fetch:] methods that supports Swift exception. @seealso [AVObject fetch:]

- (BOOL)fetchAndThrowsWithError:(NSError **)error

Discussion

An alias of [AVObject fetch:] methods that supports Swift exception. @seealso [AVObject fetch:]

Declared In

AVObject.h

– fetchWithKeys:

Fetches the AVObject with the current data and specified keys from the server and sets an error if it occurs.

- (void)fetchWithKeys:(nullable NSArray *)keys

Parameters

keys

Pointer to an NSArray that contains objects specified by the keys want to fetch.

Discussion

Fetches the AVObject with the current data and specified keys from the server and sets an error if it occurs.

Declared In

AVObject.h

– fetchWithKeys:error:

Fetches the AVObject with the current data and specified keys from the server and sets an error if it occurs.

- (BOOL)fetchWithKeys:(nullable NSArray *)keys error:(NSError **)error

Parameters

keys

Pointer to an NSArray that contains objects specified by the keys want to fetch.

error

Pointer to an NSError that will be set if necessary.

Return Value

success or not

Discussion

Fetches the AVObject with the current data and specified keys from the server and sets an error if it occurs.

Declared In

AVObject.h

– fetchIfNeeded

Fetches the AVObject’s data from the server if isDataAvailable is false.

- (AVObject *)fetchIfNeeded

Discussion

Fetches the AVObject’s data from the server if isDataAvailable is false.

Declared In

AVObject.h

– fetchIfNeeded:

Fetches the AVObject’s data from the server if isDataAvailable is false.

- (AVObject *)fetchIfNeeded:(NSError **)error

Parameters

error

Pointer to an NSError that will be set if necessary.

Discussion

Fetches the AVObject’s data from the server if isDataAvailable is false.

Declared In

AVObject.h

– fetchIfNeededAndThrowsWithError:

An alias of [AVObject fetchIfNeeded:] methods that supports Swift exception. @seealso [AVObject fetchIfNeeded:]

- (AVObject *)fetchIfNeededAndThrowsWithError:(NSError **)error

Discussion

An alias of [AVObject fetchIfNeeded:] methods that supports Swift exception. @seealso [AVObject fetchIfNeeded:]

Declared In

AVObject.h

– fetchIfNeededWithKeys:

Fetches the AVObject’s data from the server if isDataAvailable is false.

- (AVObject *)fetchIfNeededWithKeys:(nullable NSArray *)keys

Parameters

keys

Pointer to an NSArray that contains objects specified by the keys want to fetch.

Discussion

Fetches the AVObject’s data from the server if isDataAvailable is false.

Declared In

AVObject.h

– fetchIfNeededWithKeys:error:

Fetches the AVObject’s data from the server if isDataAvailable is false.

- (AVObject *)fetchIfNeededWithKeys:(nullable NSArray *)keys error:(NSError **)error

Parameters

keys

Pointer to an NSArray that contains objects specified by the keys want to fetch.

error

Pointer to an NSError that will be set if necessary.

Discussion

Fetches the AVObject’s data from the server if isDataAvailable is false.

Declared In

AVObject.h

– fetchInBackgroundWithBlock:

Fetches the AVObject asynchronously and executes the given callback block.

- (void)fetchInBackgroundWithBlock:(AVObjectResultBlock)block

Parameters

block

The block to execute. The block should have the following argument signature: (AVObject object, NSError error)

Discussion

Fetches the AVObject asynchronously and executes the given callback block.

Declared In

AVObject.h

– fetchInBackgroundWithKeys:block:

Fetches the AVObject asynchronously and executes the given callback block.

- (void)fetchInBackgroundWithKeys:(nullable NSArray *)keys block:(AVObjectResultBlock)block

Parameters

keys

Pointer to an NSArray that contains objects specified by the keys want to fetch.

block

The block to execute. The block should have the following argument signature: (AVObject object, NSError error)

Discussion

Fetches the AVObject asynchronously and executes the given callback block.

Declared In

AVObject.h

– fetchInBackgroundWithTarget:selector:

Fetches the AVObject asynchronously and calls the given callback.

- (void)fetchInBackgroundWithTarget:(id)target selector:(SEL)selector

Parameters

target

The target on which the selector will be called.

selector

The selector to call. It should have the following signature: (void)callbackWithResult:(AVObject )refreshedObject error:(NSError )error. error will be nil on success and set if there was an error. refreshedObject will be the AVObject with the refreshed data.

Discussion

Fetches the AVObject asynchronously and calls the given callback.

Declared In

AVObject.h

– fetchIfNeededInBackgroundWithBlock:

Fetches the AVObject’s data asynchronously if isDataAvailable is false, then calls the callback block.

- (void)fetchIfNeededInBackgroundWithBlock:(AVObjectResultBlock)block

Parameters

block

The block to execute. The block should have the following argument signature: (AVObject object, NSError error)

Discussion

Fetches the AVObject’s data asynchronously if isDataAvailable is false, then calls the callback block.

Declared In

AVObject.h

– fetchIfNeededInBackgroundWithTarget:selector:

Fetches the AVObject’s data asynchronously if isDataAvailable is false, then calls the callback.

- (void)fetchIfNeededInBackgroundWithTarget:(id)target selector:(SEL)selector

Parameters

target

The target on which the selector will be called.

selector

The selector to call. It should have the following signature: (void)callbackWithResult:(AVObject )fetchedObject error:(NSError )error. error will be nil on success and set if there was an error.

Discussion

Fetches the AVObject’s data asynchronously if isDataAvailable is false, then calls the callback.

Declared In

AVObject.h

Getting Many Objects from LeanCloud

+ fetchAll:

Fetches all of the AVObjects with the current data from the server

+ (void)fetchAll:(NSArray *)objects

Parameters

objects

The list of objects to fetch.

Discussion

Fetches all of the AVObjects with the current data from the server

Declared In

AVObject.h

+ fetchAll:error:

Fetches all of the AVObjects with the current data from the server and sets an error if it occurs.

+ (BOOL)fetchAll:(NSArray *)objects error:(NSError **)error

Parameters

objects

The list of objects to fetch.

error

Pointer to an NSError that will be set if necessary

Return Value

success or not

Discussion

Fetches all of the AVObjects with the current data from the server and sets an error if it occurs.

Declared In

AVObject.h

+ fetchAllIfNeeded:

Fetches all of the AVObjects with the current data from the server

+ (void)fetchAllIfNeeded:(NSArray *)objects

Parameters

objects

The list of objects to fetch.

Discussion

Fetches all of the AVObjects with the current data from the server

Declared In

AVObject.h

+ fetchAllIfNeeded:error:

Fetches all of the AVObjects with the current data from the server and sets an error if it occurs.

+ (BOOL)fetchAllIfNeeded:(NSArray *)objects error:(NSError **)error

Parameters

objects

The list of objects to fetch.

error

Pointer to an NSError that will be set if necessary

Return Value

success or not

Discussion

Fetches all of the AVObjects with the current data from the server and sets an error if it occurs.

Declared In

AVObject.h

+ fetchAllInBackground:block:

Fetches all of the AVObjects with the current data from the server asynchronously and calls the given block.

+ (void)fetchAllInBackground:(NSArray *)objects block:(AVArrayResultBlock)block

Parameters

objects

The list of objects to fetch.

block

The block to execute. The block should have the following argument signature: (NSArray objects, NSError error)

Discussion

Fetches all of the AVObjects with the current data from the server asynchronously and calls the given block.

Declared In

AVObject.h

+ fetchAllInBackground:target:selector:

Fetches all of the AVObjects with the current data from the server asynchronously and calls the given callback.

+ (void)fetchAllInBackground:(NSArray *)objects target:(id)target selector:(SEL)selector

Parameters

objects

The list of objects to fetch.

target

The target on which the selector will be called.

selector

The selector to call. It should have the following signature: (void)callbackWithResult:(NSArray )fetchedObjects error:(NSError )error. error will be nil on success and set if there was an error. fetchedObjects will the array of AVObjects that were fetched.

Discussion

Fetches all of the AVObjects with the current data from the server asynchronously and calls the given callback.

Declared In

AVObject.h

+ fetchAllIfNeededInBackground:block:

Fetches all of the AVObjects with the current data from the server asynchronously and calls the given block.

+ (void)fetchAllIfNeededInBackground:(NSArray *)objects block:(AVArrayResultBlock)block

Parameters

objects

The list of objects to fetch.

block

The block to execute. The block should have the following argument signature: (NSArray objects, NSError error)

Discussion

Fetches all of the AVObjects with the current data from the server asynchronously and calls the given block.

Declared In

AVObject.h

+ fetchAllIfNeededInBackground:target:selector:

Fetches all of the AVObjects with the current data from the server asynchronously and calls the given callback.

+ (void)fetchAllIfNeededInBackground:(NSArray *)objects target:(id)target selector:(SEL)selector

Parameters

objects

The list of objects to fetch.

target

The target on which the selector will be called.

selector

The selector to call. It should have the following signature: (void)callbackWithResult:(NSArray )fetchedObjects error:(NSError )error. error will be nil on success and set if there was an error. fetchedObjects will the array of AVObjects that were fetched.

Discussion

Fetches all of the AVObjects with the current data from the server asynchronously and calls the given callback.

Declared In

AVObject.h

Removing an Object from LeanCloud

– delete

Deletes the AVObject.

- (BOOL)delete

Return Value

whether the delete succeeded.

Discussion

Deletes the AVObject.

Declared In

AVObject.h

– delete:

Deletes the AVObject and sets an error if it occurs.

- (BOOL)delete:(NSError **)error

Parameters

error

Pointer to an NSError that will be set if necessary.

Return Value

whether the delete succeeded.

Discussion

Deletes the AVObject and sets an error if it occurs.

Declared In

AVObject.h

– deleteAndThrowsWithError:

An alias of [AVObject delete:] methods that supports Swift exception. @seealso [AVObject delete:]

- (BOOL)deleteAndThrowsWithError:(NSError **)error

Discussion

An alias of [AVObject delete:] methods that supports Swift exception. @seealso [AVObject delete:]

Declared In

AVObject.h

– deleteInBackground

Deletes the AVObject asynchronously.

- (void)deleteInBackground

Discussion

Deletes the AVObject asynchronously.

Declared In

AVObject.h

– deleteInBackgroundWithBlock:

Deletes the AVObject asynchronously and executes the given callback block.

- (void)deleteInBackgroundWithBlock:(AVBooleanResultBlock)block

Parameters

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Discussion

Deletes the AVObject asynchronously and executes the given callback block.

Declared In

AVObject.h

– deleteInBackgroundWithTarget:selector:

Deletes the AVObject asynchronously and calls the given callback.

- (void)deleteInBackgroundWithTarget:(id)target selector:(SEL)selector

Parameters

target

The object to call selector on.

selector

The selector to call. It should have the following signature: (void)callbackWithResult:(NSNumber )result error:(NSError )error. error will be nil on success and set if there was an error. [result boolValue] will tell you whether the call succeeded or not.

Discussion

Deletes the AVObject asynchronously and calls the given callback.

Declared In

AVObject.h

– deleteEventually

Deletes this object from the server at some unspecified time in the future, even if LeanCloud is currently inaccessible. Use this when you may not have a solid network connection, and don’t need to know when the delete completes. If there is some problem with the object such that it can’t be deleted, the request will be silently discarded.

- (void)deleteEventually

Discussion

Deletes this object from the server at some unspecified time in the future, even if LeanCloud is currently inaccessible. Use this when you may not have a solid network connection, and don’t need to know when the delete completes. If there is some problem with the object such that it can’t be deleted, the request will be silently discarded.

Delete instructions made with this method will be stored locally in an on-disk cache until they can be transmitted to LeanCloud. They will be sent immediately if possible. Otherwise, they will be sent the next time a network connection is available. Delete requests will persist even after the app is closed, in which case they will be sent the next time the app is opened. If more than 10MB of saveEventually or deleteEventually commands are waiting to be sent, subsequent calls to saveEventually or deleteEventually will cause old requests to be silently discarded until the connection can be re-established, and the queued requests can go through.

Declared In

AVObject.h

– deleteEventuallyWithBlock:

deleteEventually with callback block.

- (void)deleteEventuallyWithBlock:(AVIdResultBlock)block

Parameters

block

The block to execute.

Discussion

deleteEventually with callback block.

Declared In

AVObject.h

+ deleteAll:

Deletes all objects specified in object array.

+ (BOOL)deleteAll:(NSArray *)objects

Parameters

objects

object array

Return Value

whether the delete succeeded

Discussion

Deletes all objects specified in object array.

Declared In

AVObject.h

+ deleteAll:error:

Deletes all objects specified in object array.

+ (BOOL)deleteAll:(NSArray *)objects error:(NSError **)error

Parameters

objects

object array

error

Pointer to an NSError that will be set if necessary.

Return Value

whether the delete succeeded.

Discussion

Deletes all objects specified in object array.

Declared In

AVObject.h

+ deleteAllInBackground:block:

Deletes all objects specified in object array. The element of objects array is AVObject or its subclass.

+ (void)deleteAllInBackground:(NSArray *)objects block:(AVBooleanResultBlock)block

Parameters

objects

object array

block

The block to execute. The block should have the following argument signature: (BOOL succeeded, NSError *error)

Discussion

Deletes all objects specified in object array. The element of objects array is AVObject or its subclass.

Declared In

AVObject.h

  fetchWhenSave

@property (nonatomic, readwrite) BOOL fetchWhenSave

– dictionaryForObject

Generate JSON dictionary from AVObject or its subclass object.

- (NSMutableDictionary *)dictionaryForObject

Discussion

Generate JSON dictionary from AVObject or its subclass object.

Declared In

AVObject.h

+ objectWithDictionary:

Construct an AVObject or its subclass object with dictionary.

+ (nullable AVObject *)objectWithDictionary:(NSDictionary *)dictionary

Parameters

dictionary

A dictionary to construct an AVObject. The dictionary should have className key which helps to create proper class.

Discussion

Construct an AVObject or its subclass object with dictionary.

Declared In

AVObject.h

– objectFromDictionary:

Load object properties from JSON dictionary.

- (void)objectFromDictionary:(NSDictionary *)dict

Parameters

dict

JSON dictionary

Discussion

Load object properties from JSON dictionary.

Declared In

AVObject.h

AVDeprecated Methods

+ objectWithoutDataWithObjectId:

+ (instancetype)objectWithoutDataWithObjectId:(NSString *)objectId

+ objectWithoutDataWithClassName:objectId:

+ (instancetype)objectWithoutDataWithClassName:(NSString *)className objectId:(NSString *)objectId

– relationforKey:

- (AVRelation *)relationforKey:(NSString *)key

Subclass Methods

+ object

Creates an instance of the registered subclass with this class’s parseClassName. This helps a subclass ensure that it can be subclassed itself. For example, [AVUser object] will return a MyUser object if MyUser is a registered subclass of AVUser. For this reason, [MyClass object] is preferred to [[MyClass alloc] init]. This method can only be called on subclasses which conform to AVSubclassing. A default implementation is provided by AVObject which should always be sufficient.

+ (instancetype)object

Discussion

Creates an instance of the registered subclass with this class’s parseClassName. This helps a subclass ensure that it can be subclassed itself. For example, [AVUser object] will return a MyUser object if MyUser is a registered subclass of AVUser. For this reason, [MyClass object] is preferred to [[MyClass alloc] init]. This method can only be called on subclasses which conform to AVSubclassing. A default implementation is provided by AVObject which should always be sufficient.

Declared In

AVObject+Subclass.h

+ registerSubclass

Registers an Objective-C class for LeanCloud to use for representing a given LeanCloud class. Once this is called on a AVObject subclass, any AVObject LeanCloud creates with a class name matching [self parseClassName] will be an instance of subclass. This method can only be called on subclasses which conform to AVSubclassing. A default implementation is provided by AVObject which should always be sufficient.

+ (void)registerSubclass

Discussion

Registers an Objective-C class for LeanCloud to use for representing a given LeanCloud class. Once this is called on a AVObject subclass, any AVObject LeanCloud creates with a class name matching [self parseClassName] will be an instance of subclass. This method can only be called on subclasses which conform to AVSubclassing. A default implementation is provided by AVObject which should always be sufficient.

Declared In

AVObject+Subclass.h

+ query

Returns a query for objects of type +parseClassName. This method can only be called on subclasses which conform to AVSubclassing. A default implementation is provided by AVObject which should always be sufficient.

+ (AVQuery *)query

Discussion

Returns a query for objects of type +parseClassName. This method can only be called on subclasses which conform to AVSubclassing. A default implementation is provided by AVObject which should always be sufficient.

Declared In

AVObject+Subclass.h