Inherits from KiiBaseBucket : NSObject
Conforms to KiiSubscribable
Declared in KiiBucket.h

Overview

A reference to a bucket within an application, group or user’s scope which contains KiiObjects

Properties

bucketACL

Get the ACL handle for this bucket. Any KiiACLEntry objects added or revoked from this ACL object will be appended to/removed from the server on ACL save.

@property (readonly) KiiACL *bucketACL

Discussion

Get the ACL handle for this bucket. Any KiiACLEntry objects added or revoked from this ACL object will be appended to/removed from the server on ACL save.

Declared In

KiiBucket.h

Class Methods

isValidBucketName:

Checks whether the bucket name is valid or not.

+ (BOOL)isValidBucketName:(nullable NSString *)bucketName

Parameters

bucketName

Name of the bucket.

Return Value

YES if valid otherwise NO.

Discussion

Checks whether the bucket name is valid or not.

Valid bucket name definition is:

- Not null or empty
- Matches ^[a-zA-Z0-9-_]{2,64}$

Declared In

KiiBucket.h

Instance Methods

count:

Asynchronously execute count aggregation of all clause query on current bucket. This is non-blocking method.

- (void)count:(KiiCountQueryResultBlock)block

Parameters

block

The block to be called upon method completion. See example.

Discussion

Asynchronously execute count aggregation of all clause query on current bucket. This is non-blocking method.

    KiiBucket *bucket = ...;
    [bucket count:^(KiiBucket *bucket, KiiQuery *query, NSUInteger result, NSError *error){

        if(error){
            // do something with error;
            return;
        }

        NSLog(@"count :%d",result);

    };

Declared In

KiiBucket.h

countObjectsSynchronous:

Synchronously execute count aggregation of all clause query on current bucket. This is blocking method.

- (nullable NSNumber *)countObjectsSynchronous:(NSError *_Nullable *_Nullable)error

Parameters

error

used to return an error by reference (pass NULL if this is not desired). It is recommended to set an actual error object to get the error information.

Return Value

NSNumber number of object inside the current bucket in unsigned integer format, nil if error.

Discussion

Synchronously execute count aggregation of all clause query on current bucket. This is blocking method.

Declared In

KiiBucket.h

countObjectsSynchronous:error:

Synchronously execute count aggregation of specific query on current bucket. This is blocking method.

- (nullable NSNumber *)countObjectsSynchronous:(nullable KiiQuery *)query error:(NSError *_Nullable *_Nullable)error

Parameters

query

The query to execute. If nil, KiiQuery with all clause wil be set by default.

error

used to return an error by reference (pass NULL if this is not desired). It is recommended to set an actual error object to get the error information.

Return Value

NSNumber number of object inside the current bucket in unsigned integer format, nil if error.

Discussion

Synchronously execute count aggregation of specific query on current bucket. This is blocking method.

Do not pass query from next query of executeQuerySynchronous:withError:andNext: or nextQuery from callback/block, otherwise an error (code 604) will be returned.

If the given query is not supported, an error (code 604) will be returned.

Declared In

KiiBucket.h

countSynchronous:

Depreacated. Use countObjectsSynchronous:error

- (NSUInteger)countSynchronous:(NSError *_Nullable *_Nullable)error

Discussion

Depreacated. Use countObjectsSynchronous:error

Declared In

KiiBucket.h

countSynchronousWithQuery:andError:

- (NSUInteger)countSynchronousWithQuery:(nullable KiiQuery *)query andError:(NSError *_Nullable *_Nullable)error

Declared In

KiiBucket.h

countWithQuery:andBlock:

Asynchronously execute count aggregation of specific query on current bucket. This is non-blocking method.

- (void)countWithQuery:(nullable KiiQuery *)query andBlock:(KiiCountQueryResultBlock)block

Parameters

query

The query to execute. If nil, KiiQuery with all clause wil be set by default.

block

The block to be called upon method completion. See example.

Discussion

Asynchronously execute count aggregation of specific query on current bucket. This is non-blocking method.

Do not pass query from next query of executeQuerySynchronous:withError:andNext: or nextQuery from callback/block, otherwise an error (code 604) will be returned.

If the given query is not supported, an error (code 604) will be returned.

    KiiBucket *bucket = ...;
    KiiQuery *query = ...;
    [bucket countWithQuery:query andBlock:^(KiiBucket *bucket, KiiQuery *query, NSUInteger result, NSError *error){

        if(error){
        // do something with error;
        return;
        }

        NSLog(@"count :%d",result);
    };

Declared In

KiiBucket.h

createObject

Create a KiiObject within the current bucket

- (KiiObject *)createObject

Return Value

An empty KiiObject with the specified type

Discussion

Create a KiiObject within the current bucket

The object will not be created on the server until the KiiObject is explicitly saved. This method simply returns an empty working KiiObject.

Declared In

KiiBucket.h

createObjectWithID:

Instantiate KiiObject specifying its ID.

- (KiiObject *)createObjectWithID:(NSString *)objectID

Parameters

objectID

The ID of the KiiObject you’d like to use. It has to match the pattern with: ^[a-zA-Z0-9-_\.]{2,100}$

Return Value

A KiiObject instance.

Discussion

Instantiate KiiObject specifying its ID.

If the object has not existed on KiiCloud, <saveAllFieldsSynchronous:withError:>, <saveAllFields:withBlock:> or <saveAllFields:withDelegate:andCallback:> will create new Object which has ID specified in the argument. If the object exists in KiiCloud, references the existing object which has specified ID, use <KiiObject#refreshSynchronous:> to retrieve the contents of KiiObject.

Exceptions

NSInvalidArgumentException

Thrown if objectID is not acceptable.

Declared In

KiiBucket.h

createObjectWithType:

Create a KiiObject within the current bucket, with type

- (KiiObject *)createObjectWithType:(nullable NSString *)objectType

Parameters

objectType

A string representing the desired object type

Return Value

An empty KiiObject with the specified type

Discussion

Create a KiiObject within the current bucket, with type

The object will not be created on the server until the KiiObject is explicitly saved. This method simply returns an empty working KiiObject with a specified type. The type allows for better indexing and improved query results. It is recommended to use this method - but for lazy creation, the createObject method is also available.

Declared In

KiiBucket.h

delete:withCallback:

Asynchronously deletes a bucket from the server.

- (void)delete:(id)delegate withCallback:(SEL)callback

Parameters

delegate

The object to make any callback requests to

callback

The callback method to be called when the request is completed. The callback method should have a signature similar to:

 - (void) bucketDeleted:(KiiBucket*)bucket withError:(NSError*)error {

    // the request was successful
    if(error == nil) {
        // do something
    }

    else {
        // there was a problem
    }
 }

Discussion

Asynchronously deletes a bucket from the server.

Delete a bucket from the server. This method is non-blocking.

Declared In

KiiBucket.h

deleteSynchronous:

Synchronously deletes a bucket from the server.

- (BOOL)deleteSynchronous:(NSError *_Nullable *_Nullable)error

Parameters

error

used to return an error by reference (pass NULL if this is not desired). It is recommended to set an actual error object to get the error information.

Return Value

YES if succeeded, NO otherwise.

Discussion

Synchronously deletes a bucket from the server.

Delete a bucket from the server. This method is blocking.

Declared In

KiiBucket.h

deleteWithBlock:

Asynchronously deletes a bucket from the server.

- (void)deleteWithBlock:(KiiBucketBlock)block

Parameters

block

The block to be called upon method completion. See example

Discussion

Asynchronously deletes a bucket from the server.

Delete a bucket from the server. This method is non-blocking.

 [b deleteWithBlock:^(KiiBucket *bucket, NSError *error) {
     if(error == nil) {
         NSLog(@"Bucket deleted!");
     }
 }];

Declared In

KiiBucket.h

executeQuery:withBlock:

Execute a query on the current bucket

- (void)executeQuery:(nullable KiiQuery *)query withBlock:(KiiQueryResultBlock)block

Parameters

query

The query to execute. If nil, fetch all items in the bucket.

block

The block to be called upon method completion. See example

Discussion

Execute a query on the current bucket

The query will be executed against the server, returning a result set. This is a blocking method

KiiBucket *bucket = ...;
KiiQuery *query = ...;

// To recursively get all results in a query (from multiple pages)
KiiQueryResultBlock __block __weak weakQueryBlock;
KiiQueryResultBlock queryBlock = ^(KiiQuery *retQuery, KiiBucket *retBucket, NSArray *retResults, KiiQuery *retNextQuery, NSError *retError) {
    // We got some valid results
    if (retError == nil) {
        // Do something with the results
        [self handleResults:retResults];
    }

    // We have another query available (another page of results)
    if (retNextQuery != nil) {
        // Execute the next query
        [bucket executeQuery:retNextQuery withBlock:[weakQueryBlock copy]];
    }
};
weakQueryBlock = queryBlock;

[bucket executeQuery:query withBlock:queryBlock];

Declared In

KiiBucket.h

executeQuery:withDelegate:andCallback:

Execute a query on the current bucket

- (void)executeQuery:(nullable KiiQuery *)query withDelegate:(id)delegate andCallback:(SEL)callback

Parameters

query

The query to execute. If nil, fetch all items in the bucket.

delegate

The object to make any callback requests to

callback

The callback method to be called when the request is completed. The callback method should have a signature similar to:

- (void)queryFinished:(KiiQuery *)query onBucket:(KiiBucket *)bucket withResults:(NSArray *)results andNext:(KiiQuery *)nextQuery andError:(NSError *)error {
    // The request was successful
    if (error == nil) {
        // Do something with the results
        for (KiiObject *o in results) {
            // use this object
        }

        // Also check to see if there are more results
        if (nextQuery != nil) {
            // There are more results, query for them
            [bucket executeQuery:nextQuery withDelegate:self andCallback:@selector(queryFinished:onBucket:withResults:andNext:andError:)];
        }
    } else {
        // there was a problem
    }
}

Discussion

Execute a query on the current bucket

The query will be executed against the server, returning a result set. This is a non-blocking method

Declared In

KiiBucket.h

executeQuerySynchronous:nextQuery:error:

Execute a query on the current bucket

- (nullable NSArray *)executeQuerySynchronous:(nullable KiiQuery *)query nextQuery:(KiiQuery *_Nullable *_Nullable)nextQuery error:(NSError *_Nullable *_Nullable)error

Parameters

query

The query to execute. If nil, fetch all items in the bucket.

nextQuery

A KiiQuery object representing the next set of results, if they couldn’t all be returned in the current query

error

used to return an error by reference (pass NULL if this is not desired). It is recommended to set an actual error object to get the error information.

Return Value

An NSArray of objects returned by the query.

KiiBucket *bucket = ...;
KiiQuery *query = ...;
NSError *error = nil;
KiiQuery *nextQuery = nil;
NSMutableArray *allResults = [NSMutableArray array];

do {
    if (nextQuery != nil) {
        // Set next query
        query = nextQuery;
    }
    // Do query
    NSArray *results = [bucket executeQuerySynchronous:query withError:&error nextQuery:&nextQuery];
    // Add results to the all results array
    [allResults addObjectsFromArray:results];
} while (error == nil && nextQuery != nil);

// Do something with the entire result set contained in allResults

Discussion

Execute a query on the current bucket

The query will be executed against the server, returning a result set. This is a blocking method

Declared In

KiiBucket.h

executeQuerySynchronous:withError:andNext:

- (nullable NSArray *)executeQuerySynchronous:(nullable KiiQuery *)query withError:(NSError *_Nullable *_Nullable)error andNext:(KiiQuery *_Nullable *_Nullable)nextQuery

Declared In

KiiBucket.h

transferManager

Get transfer manager object based on this bucket

- (KiiRTransferManager *)transferManager

Return Value

A transfer manager object based on this file bucket.

Discussion

Get transfer manager object based on this bucket

Declared In

KiiBucket.h