Other Type Definitions

The following type definitions are available globally.

  • Undocumented

    Declaration

    Objective-C

    typedef void (^YapActionItemBlock)(NSString *collection, NSString *key, id object, _Nullable id metadata)

    Swift

    typealias YapActionItemBlock = (String, String, Any, Any?) -> Void
  • Undocumented

    Declaration

    Objective-C

    typedef NSArray<YapActionItem*> *_Nullable (^YapActionScheduler)(NSString *collection, NSString *key, id object)

    Swift

    typealias YapActionScheduler = (String, String, Any) -> [YapActionItem]?
  • Undocumented

    Declaration

    Objective-C

    typedef id YapDatabaseViewSortingBlock

    Swift

    typealias YapDatabaseViewSortingBlock = AnyObject
  • Undocumented

    Declaration

    Objective-C

    typedef NSComparisonResult (^YapDatabaseViewSortingWithKeyBlock)
                     (YapDatabaseReadTransaction *transaction, NSString *group,
                          NSString *collection1, NSString *key1,
                          NSString *collection2, NSString *key2)

    Swift

    typealias YapDatabaseViewSortingWithKeyBlock = (YapDatabaseReadTransaction, String, String, String, String, String) -> ComparisonResult
  • Undocumented

    Declaration

    Objective-C

    typedef NSComparisonResult (^YapDatabaseViewSortingWithObjectBlock)
                     (YapDatabaseReadTransaction *transaction, NSString *group,
                          NSString *collection1, NSString *key1, id object1,
                          NSString *collection2, NSString *key2, id object2)

    Swift

    typealias YapDatabaseViewSortingWithObjectBlock = (YapDatabaseReadTransaction, String, String, String, Any, String, String, Any) -> ComparisonResult
  • Undocumented

    Declaration

    Objective-C

    typedef NSComparisonResult (^YapDatabaseViewSortingWithMetadataBlock)
                     (YapDatabaseReadTransaction *transaction, NSString *group,
                          NSString *collection1, NSString *key1, _Nullable id metadata,
                          NSString *collection2, NSString *key2, _Nullable id metadata2)

    Swift

    typealias YapDatabaseViewSortingWithMetadataBlock = (YapDatabaseReadTransaction, String, String, String, Any?, String, String, Any?) -> ComparisonResult
  • Undocumented

    Declaration

    Objective-C

    typedef NSComparisonResult (^YapDatabaseViewSortingWithRowBlock)
                     (YapDatabaseReadTransaction *transaction, NSString *group,
                          NSString *collection1, NSString *key1, id object1, _Nullable id metadata1,
                          NSString *collection2, NSString *key2, id object2, _Nullable id metadata2)

    Swift

    typealias YapDatabaseViewSortingWithRowBlock = (YapDatabaseReadTransaction, String, String, String, Any, Any?, String, String, Any, Any?) -> ComparisonResult
  • Undocumented

    Declaration

    Objective-C

    typedef id YapDatabaseViewFindBlock

    Swift

    typealias YapDatabaseViewFindBlock = AnyObject
  • Undocumented

    Declaration

    Objective-C

    typedef NSComparisonResult (^YapDatabaseViewFindWithKeyBlock)
                                     (NSString *collection, NSString *key)

    Swift

    typealias YapDatabaseViewFindWithKeyBlock = (String, String) -> ComparisonResult
  • Undocumented

    Declaration

    Objective-C

    typedef NSComparisonResult (^YapDatabaseViewFindWithObjectBlock)
                                     (NSString *collection, NSString *key, id object)

    Swift

    typealias YapDatabaseViewFindWithObjectBlock = (String, String, Any) -> ComparisonResult
  • Undocumented

    Declaration

    Objective-C

    typedef NSComparisonResult (^YapDatabaseViewFindWithMetadataBlock)
                                     (NSString *collection, NSString *key, _Nullable id metadata)

    Swift

    typealias YapDatabaseViewFindWithMetadataBlock = (String, String, Any?) -> ComparisonResult
  • Undocumented

    Declaration

    Objective-C

    typedef NSComparisonResult (^YapDatabaseViewFindWithRowBlock)
                                     (NSString *collection, NSString *key, id object, _Nullable id metadata)

    Swift

    typealias YapDatabaseViewFindWithRowBlock = (String, String, Any, Any?) -> ComparisonResult
  • When YapDatabaseCloudKit goes to push a change-set to the server, it creates a CKModifyRecordsOperation. If that operation comes back with an error from the CloudKit Framework, then YapDatabaseCloudKit automatically suspends itself, and forwards the error to you via the OperationErrorBlock.

    It’s your job to look at the errorCode, decide what to do, and resume YapDatabaseCloudKit when ready.

    For more information, please see the wiki: https://github.com/yapstudios/YapDatabase/wiki/YapDatabaseCloudKit#OperationErrorBlock

    Declaration

    Objective-C

    typedef void (^YapDatabaseCloudKitOperationErrorBlock)(NSString *_Nonnull,
                                                           NSError *_Nonnull)

    Swift

    typealias YapDatabaseCloudKitOperationErrorBlock = (String, Error) -> Void
  • DatabaseIdentifier Block.

    CloudKit supports multiple databases. There is the privateCloudDatabase & publicCloudDatabase of the defaultContainer. In addition to this, apps may be configured with access to other (non-default) containers.

    In order to properly support multiple databases, the DatabaseIdentifier block is used. Here’s how it works:

    The recordHandler block is used to provide a CKRecord for a given row in the database. In addition to the CKRecord, you may also specify a ‘databaseIdentifier’ via the YDBCKRecordInfo parameter. If you specify a databaseIdentifier, then this method will be used in order to get an appropriate CKDatabase instance for the databaseIdentifier you specified.

    If you ONLY use [[CKContainer defaultContainer] privateCloudDatabase], then you do NOT need to specify a DatabaseIdentifierBlock.

    That is, if you never specify a databaseIdentifier for any records (you leave recordInfo.databaseIdentifier nil), then YapDatabaseCloudKit will assume & use [[CKContainer defaultContainer] privateCloudDatabase] for every CKRecord.

    However, if you intend to use any other CKDatabase, the you MUST provide a DatabaseIdentifierBlock.

    For more information & sample code, please see the wiki: https://github.com/yapstudios/YapDatabase/wiki/YapDatabaseCloudKit#The_databaseIdentifier

    Declaration

    Objective-C

    typedef CKDatabase *_Nullable (^YapDatabaseCloudKitDatabaseIdentifierBlock)(
        NSString *_Nonnull)

    Swift

    typealias YapDatabaseCloudKitDatabaseIdentifierBlock = (String) -> CKDatabase?
  • Undocumented

    Declaration

    Objective-C

    typedef id YapDatabaseRTreeIndexBlock

    Swift

    typealias YapDatabaseRTreeIndexBlock = AnyObject
  • Undocumented

    Declaration

    Objective-C

    typedef void (^YapDatabaseRTreeIndexWithKeyBlock)
                                (NSMutableDictionary *dict, NSString *collection, NSString *key)

    Swift

    typealias YapDatabaseRTreeIndexWithKeyBlock = (NSMutableDictionary, String, String) -> Void
  • Undocumented

    Declaration

    Objective-C

    typedef void (^YapDatabaseRTreeIndexWithObjectBlock)
                                (NSMutableDictionary *dict, NSString *collection, NSString *key, id object)

    Swift

    typealias YapDatabaseRTreeIndexWithObjectBlock = (NSMutableDictionary, String, String, Any) -> Void
  • Undocumented

    Declaration

    Objective-C

    typedef void (^YapDatabaseRTreeIndexWithMetadataBlock)
                                (NSMutableDictionary *dict, NSString *collection, NSString *key, __nullable id metadata)

    Swift

    typealias YapDatabaseRTreeIndexWithMetadataBlock = (NSMutableDictionary, String, String, Any?) -> Void
  • Undocumented

    Declaration

    Objective-C

    typedef void (^YapDatabaseRTreeIndexWithRowBlock)
                                (NSMutableDictionary *dict, NSString *collection, NSString *key, id object, __nullable id metadata)

    Swift

    typealias YapDatabaseRTreeIndexWithRowBlock = (NSMutableDictionary, String, String, Any, Any?) -> Void
  • The FileURLSerializer & FileURLDeserializer are used to convert between NSURL and the (serialized) blob (of bytes) that goes into the database.

    By default the system converts the NSURL to a bookmark so that, even if the file is moved, the deserialized NSURL will point to the new filePath.

    You can override this behavior to achieve alternative goals.

    See

    defaultFileURLSerializer

    See

    defaultFileURLDeserializer

    Declaration

    Objective-C

    typedef NSData *_Nullable (^YapDatabaseRelationshipFileURLSerializer)(
        YapDatabaseRelationshipEdge *_Nonnull)

    Swift

    typealias YapDatabaseRelationshipFileURLSerializer = (YapDatabaseRelationshipEdge) -> Data?
  • Undocumented

    Declaration

    Objective-C

    typedef NSURL* _Nullable (^YapDatabaseRelationshipFileURLDeserializer)(YapDatabaseRelationshipEdge *edge, NSData *data)

    Swift

    typealias YapDatabaseRelationshipFileURLDeserializer = (YapDatabaseRelationshipEdge, Data) -> URL?
  • Starting with v2.8, YapDatabaseRelationship extension uses NSURL to represent destination files.

    Prior to this, it used string-based file paths. These proved especially brittle after Apple started moving app folders around in iOS (~ Xcode 6 & iOS 8).

    During the upgrade process (performed when the extension is registered), the migration block can be used to convert previous filePaths to NSURL’s.

    Only one of the parameters will be non-nil.

    Declaration

    Objective-C

    typedef NSURL *_Nullable (^YapDatabaseRelationshipMigration)(
        NSString *_Nullable, NSData *_Nullable)

    Swift

    typealias YapDatabaseRelationshipMigration = (String?, Data?) -> URL?

    Parameters

    filePath

    The original filePath that was given to the relationship extension

    data

    The encrypted filePath, generated from a previously configured filePathEncryption block.

  • Undocumented

    Declaration

    Objective-C

    typedef BOOL (^YapWhitelistBlacklistFilterBlock)(id item)

    Swift

    typealias YapWhitelistBlacklistFilterBlock = (Any) -> Bool
  • How does YapDatabase store my objects to disk?

    That question is answered extensively in the wiki article Storing Objects: https://github.com/yapstudios/YapDatabase/wiki/Storing-Objects

    Here’s the intro from the wiki article:

    In order to store an object to disk (via YapDatabase or any other protocol) you need some way of serializing the object. That is, convert the object into a big blob of bytes. And then, to get your object back from the disk you deserialize it (convert big blob of bytes back into object form).

    With YapDatabase, you can choose your preferred serialization/deserialization process.

    In order to support adding objects to the database, serializers and deserializers are used. The serializer and deserializer are just simple blocks that you can optionally configure.

    The default serializer/deserializer uses NSCoding. This is suitable for Objective-C, but not for Swift.

    For Swift: It’s likely you’ll prefer to use the Codable protocol. To do so, you simply register your Codable class for the corresponding collection:

     database.registerCodableSerialization(String.self, forCollection: "foo")
     database.registerCodableSerialization(MyCodableClass.self, forCollection: "bar")
    

    For Objective-C: The default serializer & deserializer use NSCoding (NSKeyedArchiver & NSKeyedUnarchiver). Most of Apple’s primary data types support NSCoding out of the box. And it’s easy to add NSCoding support to your own custom objects.

     defaultSerializer = ^(NSString *collection, NSString *key, id object){
         return [NSKeyedArchiver archivedDataWithRootObject:object];
     };
     defaultDeserializer = ^(NSString *collection, NSString *key, NSData *data) {
         return [NSKeyedUnarchiver unarchiveObjectWithData:data];
     };
    

    Declaration

    Objective-C

    typedef NSData *_Nonnull (^YapDatabaseSerializer)(NSString *_Nonnull,
                                                      NSString *_Nonnull,
                                                      id _Nonnull)

    Swift

    typealias YapDatabaseSerializer = (String, String, Any) -> Data
  • How does YapDatabase store my objects to disk?

    That question is answered extensively in the wiki article Storing Objects: https://github.com/yapstudios/YapDatabase/wiki/Storing-Objects

    Here’s the intro from the wiki article:

    In order to store an object to disk (via YapDatabase or any other protocol) you need some way of serializing the object. That is, convert the object into a big blob of bytes. And then, to get your object back from the disk you deserialize it (convert big blob of bytes back into object form).

    With YapDatabase, you can choose your preferred serialization/deserialization process.

    In order to support adding objects to the database, serializers and deserializers are used. The serializer and deserializer are just simple blocks that you can optionally configure.

    The default serializer/deserializer uses NSCoding. This is suitable for Objective-C, but not for Swift.

    For Swift: It’s likely you’ll prefer to use the Codable protocol. To do so, you simply register your Codable class for the corresponding collection:

     database.registerCodableSerialization(String.self, forCollection: "foo")
     database.registerCodableSerialization(MyCodableClass.self, forCollection: "bar")
    

    For Objective-C: The default serializer & deserializer use NSCoding (NSKeyedArchiver & NSKeyedUnarchiver). Most of Apple’s primary data types support NSCoding out of the box. And it’s easy to add NSCoding support to your own custom objects.

     defaultSerializer = ^(NSString *collection, NSString *key, id object){
         return [NSKeyedArchiver archivedDataWithRootObject:object];
     };
     defaultDeserializer = ^(NSString *collection, NSString *key, NSData *data) {
         return [NSKeyedUnarchiver unarchiveObjectWithData:data];
     };
    

    Declaration

    Objective-C

    typedef id _Nullable (^YapDatabaseDeserializer)(NSString *_Nonnull,
                                                    NSString *_Nonnull,
                                                    NSData *_Nonnull)

    Swift

    typealias YapDatabaseDeserializer = (String, String, Data) -> Any?
  • The sanitizer block allows you to enforce desired behavior of the objects you put into the database.

    If set, the sanitizer block will be run on all items being input into the database via the setObject:forKey:inCollection: (and other setObject:XXX: methods).

    You have 2 different hooks for running a sanitizer block:

    The PreSanitizer is run:

    • Before the object is serialized
    • Before the object is stored in the cache
    • Before the object is passed to extensions

    The PostSanitizer is run:

    • After the object has been serialized
    • After the object has been stored in the cache
    • After the object has been passed to extensions

    The PreSanitizer is generally used validate the objects going into the database, and/or to enforce immutability of those objects.

    Enforcing immutability is a topic covered in the Object Policy wiki article: https://github.com/yapstudios/YapDatabase/wiki/Object-Policy

    The PostSanitizer is generally used to clear flags that are used by extensions. For example, your objects might have a changedProperties property that tells extensions exactly what properties where changed on a modified object. And the extension uses that information in order to automatically sync the changes to the cloud. Thus the PostSanitizer would be used to clear the changedProperties after the extension has processed the modified object.

    An example of such a use for the PostSanitizer is discussed in the YapDatabaseCloudKit wiki article: https://github.com/yapstudios/YapDatabase/wiki/YapDatabaseCloudKit

    Declaration

    Objective-C

    typedef id _Nonnull (^YapDatabasePreSanitizer)(NSString *_Nonnull,
                                                   NSString *_Nonnull, id _Nonnull)

    Swift

    typealias YapDatabasePreSanitizer = (String, String, Any) -> Any
  • The sanitizer block allows you to enforce desired behavior of the objects you put into the database.

    If set, the sanitizer block will be run on all items being input into the database via the setObject:forKey:inCollection: (and other setObject:XXX: methods).

    You have 2 different hooks for running a sanitizer block:

    The PreSanitizer is run:

    • Before the object is serialized
    • Before the object is stored in the cache
    • Before the object is passed to extensions

    The PostSanitizer is run:

    • After the object has been serialized
    • After the object has been stored in the cache
    • After the object has been passed to extensions

    The PreSanitizer is generally used validate the objects going into the database, and/or to enforce immutability of those objects.

    Enforcing immutability is a topic covered in the Object Policy wiki article: https://github.com/yapstudios/YapDatabase/wiki/Object-Policy

    The PostSanitizer is generally used to clear flags that are used by extensions. For example, your objects might have a changedProperties property that tells extensions exactly what properties where changed on a modified object. And the extension uses that information in order to automatically sync the changes to the cloud. Thus the PostSanitizer would be used to clear the changedProperties after the extension has processed the modified object.

    An example of such a use for the PostSanitizer is discussed in the YapDatabaseCloudKit wiki article: https://github.com/yapstudios/YapDatabase/wiki/YapDatabaseCloudKit

    Declaration

    Objective-C

    typedef void (^YapDatabasePostSanitizer)(NSString *_Nonnull, NSString *_Nonnull,
                                             id _Nonnull)

    Swift

    typealias YapDatabasePostSanitizer = (String, String, Any) -> Void