![]() |
Couchbase Lite
Objective-C API for iOS and Mac OS
|
Top-level Couchbase Lite object; manages a collection of databases.
A CBLManager and all the objects descending from it may only be used on a single thread. To work with databases on another thread, copy the database manager (by calling -copy) and use the copy on the other thread.
Instance Methods | |
| (instancetype) | - init |
| Default initializer. More... | |
| (nullable instancetype) | - initWithDirectory:options:error: |
| Initializes a CouchbaseLite manager that stores its data at the given path. More... | |
| (instancetype) | - copy |
| Creates a copy of this CBLManager, which can be used on a different thread. More... | |
| (void) | - close |
| Releases all resources used by the CBLManager instance and closes all its databases. More... | |
| (nullable CBLDatabase *) | - databaseNamed:error: |
| Returns the database with the given name, creating it if it didn't already exist. More... | |
| (nullable CBLDatabase *) | - existingDatabaseNamed:error: |
| Returns the database with the given name, or nil if it doesn't exist. More... | |
| (nullable CBLDatabase *) | - openDatabaseNamed:withOptions:error: |
| Returns the database with the given name. More... | |
| (BOOL) | - databaseExistsNamed: |
| Returns YES if a database with the given name exists. More... | |
| (nullable CBLDatabase *) | - objectForKeyedSubscript: |
| Same as -existingDatabaseNamed:. More... | |
| () | - CBLArrayOf |
| An array of the names of all existing databases. More... | |
| (BOOL) | - replaceDatabaseNamed:withDatabaseDir:error: |
| Replaces or installs a database from a file. More... | |
| (void) | - doAsync: |
| Runs the block asynchronously on the database manager's dispatch queue or thread. More... | |
| (void) | - backgroundTellDatabaseNamed:to: |
| Asynchronously dispatches a block to run on a background thread. More... | |
| (BOOL) | - registerEncryptionKey:forDatabaseNamed: |
| This method has been superseded by -openDatabaseNamed:options:error:. More... | |
Class Methods | |
| (instancetype) | + sharedInstance |
| A shared per-process instance. More... | |
| (BOOL) | + isValidDatabaseName: |
| Returns YES if the given name is a valid database name. More... | |
| (NSString *) | + defaultDirectory |
| The default directory to use for a CBLManager. More... | |
| (void) | + enableLogging: |
| Enables Couchbase Lite logging of the given type, process-wide. More... | |
| (void) | + redirectLogging: |
| Redirects Couchbase Lite logging: instead of writing to the console/stderr, it will call the given block. More... | |
Properties | |
| NSString * | storageType |
| Default storage engine type for newly-created databases. More... | |
| NSString * | directory |
| The root directory of this manager (as specified at initialization time.) More... | |
| BOOL | excludedFromBackup |
| Should the databases and attachments be excluded from iCloud or Time Machine backup? Defaults to NO. More... | |
| dispatch_queue_t | dispatchQueue |
| The dispatch queue used to serialize access to the database manager (and its child objects.) Setting this is optional: by default the objects are bound to the thread on which the database manager was instantiated. More... | |
| NSURL * | internalURL |
| The base URL of the database manager's REST API. More... | |
| NSMutableDictionary * | customHTTPHeaders |
| + (instancetype) sharedInstance |
A shared per-process instance.
This should only be used on the main thread.
| + (BOOL) isValidDatabaseName: | (NSString *) | name |
Returns YES if the given name is a valid database name.
(Only the characters in "abcdefghijklmnopqrstuvwxyz0123456789_$()+-/" are allowed.)
| + (NSString*) defaultDirectory |
The default directory to use for a CBLManager.
This is in the Application Support directory.
| - (instancetype) init |
Default initializer.
Stores databases in the default directory.
| - (nullable instancetype) initWithDirectory: | (NSString *) | directory | |
| options: | (const CBLManagerOptions *__nullable) | options | |
| error: | (NSError **) | outError | |
Initializes a CouchbaseLite manager that stores its data at the given path.
| directory | Path to data directory. If it doesn't already exist it will be created. |
| options | If non-NULL, a pointer to options (read-only and no-replicator). |
| outError | On return, the error if any. |
| - (instancetype) copy |
Creates a copy of this CBLManager, which can be used on a different thread.
| - (void) close |
Releases all resources used by the CBLManager instance and closes all its databases.
| - (nullable CBLDatabase*) databaseNamed: | (NSString *) | name | |
| error: | (NSError **) | outError | |
Returns the database with the given name, creating it if it didn't already exist.
Multiple calls with the same name will return the same CBLDatabase instance. NOTE: Database names may not contain capital letters! This is equivalent to calling -openDatabaseNamed:withOptions:error: with a default set of options with the create flag set.
| - (nullable CBLDatabase*) existingDatabaseNamed: | (NSString *) | name | |
| error: | (NSError **) | outError | |
Returns the database with the given name, or nil if it doesn't exist.
Multiple calls with the same name will return the same CBLDatabase instance. This is equivalent to calling -openDatabaseNamed:withOptions:error: with a default set of options.
| - (nullable CBLDatabase*) openDatabaseNamed: | (NSString *) | name | |
| withOptions: | (nullable CBLDatabaseOptions *) | options | |
| error: | (NSError **) | outError | |
Returns the database with the given name.
If the database is not yet open, the options given will be applied; if it's already open, the options are ignored. Multiple calls with the same name will return the same CBLDatabase instance.
| name | The name of the database. May NOT contain capital letters! |
| options | Options to use when opening, such as the encryption key; if nil, a default set of options will be used. |
| outError | On return, the error if any. |
| - (BOOL) databaseExistsNamed: | (NSString *) | name |
Returns YES if a database with the given name exists.
Does not open the database.
| - (nullable CBLDatabase*) objectForKeyedSubscript: | (NSString *) | key |
Same as -existingDatabaseNamed:.
Enables "[]" access in Xcode 4.4+
| - CBLArrayOf | (NSString *) |
An array of the names of all existing databases.
| - (BOOL) replaceDatabaseNamed: | (NSString *) | databaseName | |
| withDatabaseDir: | (NSString *) | databaseDir | |
| error: | (NSError **) | outError | |
Replaces or installs a database from a file.
This is primarily used to install a canned database on first launch of an app, in which case you should first check .exists to avoid replacing the database if it exists already. The canned database would have been copied into your app bundle at build time. If the database file is not a directory and has the .cblite extension, use -replaceDatabaseNamed:withDatabaseFile:withAttachments:error: instead.
| databaseName | The name of the database to replace. |
| databaseDir | Path of the database directory that should replace it. |
| outError | If an error occurs, it will be stored into this parameter on return. |
| - (void) doAsync: | (void(^)()) | block |
Runs the block asynchronously on the database manager's dispatch queue or thread.
Unlike the rest of the API, this can be called from any thread, and provides a limited form of multithreaded access to Couchbase Lite.
| - (void) backgroundTellDatabaseNamed: | (NSString *) | dbName | |
| to: | (void(^)(CBLDatabase *)) | block | |
Asynchronously dispatches a block to run on a background thread.
The block will be given a CBLDatabase instance to use; it must use that database instead of any CBL objects that are in use on the surrounding code's thread. Otherwise thread-safety will be violated, and Really Bad Things that are intermittent and hard to debug can happen. (Note: Unlike most of the API, this method is thread-safe.)
| + (void) enableLogging: | (nullable NSString *) | type |
Enables Couchbase Lite logging of the given type, process-wide.
A partial list of types is here: http://docs.couchbase.com/couchbase-lite/cbl-ios/#useful-logging-channels It's usually more convenient to enable logging via command-line args, as discussed on that same page; but in some environments you may not have access to the args, or may want to use other criteria to enable logging.
| + (void) redirectLogging: | (nullable void(^)(NSString *type, NSString *message)) | callback |
Redirects Couchbase Lite logging: instead of writing to the console/stderr, it will call the given block.
Passing a nil block restores the default behavior.
| - (BOOL) registerEncryptionKey: | (nullable id) | keyOrPassword | |
| forDatabaseNamed: | (NSString *) | name | |
This method has been superseded by -openDatabaseNamed:options:error:.
|
readwritenonatomiccopy |
Default storage engine type for newly-created databases.
There are two options, "SQLite" (the default) or "ForestDB".
|
readatomicassign |
The root directory of this manager (as specified at initialization time.)
|
readwriteatomic |
Should the databases and attachments be excluded from iCloud or Time Machine backup? Defaults to NO.
|
readwriteatomicstrong |
The dispatch queue used to serialize access to the database manager (and its child objects.) Setting this is optional: by default the objects are bound to the thread on which the database manager was instantiated.
By setting a dispatch queue, you can call the objects from within that queue no matter what the underlying thread is, and notifications will be posted on that queue as well.
|
readatomicassign |
The base URL of the database manager's REST API.
You can access this URL within this process, using NSURLConnection or other APIs that use that (such as XMLHTTPRequest inside a WebView), but it isn't available outside the process. This method is only available if you've linked with the CouchbaseLiteListener framework.
|
readnonatomicassign |