Skip to content

YapDatabaseView in Swift #91

@seeker12

Description

@seeker12

Initial setup per @zenkimoto in issue #85 (Thanks)

I'm having a problem setting up a YapDatabaseView. From my view controller's viewDidLoad: method I try to get a view instance from the following Swift func. The compiler error is, "Could not find overload for 'init' that accepts the supplied arguments". I've tried every init syntax combination of labels I could think of with no luck, although as I understand from the WWDC 2014 "Integrating Swift with Objective-C" video, the following should work.

Note that in order to resolve needed symbols I had to add a number of #import statements to ${PODS_ROOT}/Headers/YapDatabase/YapDatabase.h. I am able to initialize stored YapDatabase property instance in the view controller initializer.

func albumDbView() -> YapDatabaseView {    
        var groupingBlockType: YapDatabaseViewBlockType = YapDatabaseViewBlockTypeWithObject
        var groupingBlock = {
            (collection: String!, key: String!, object: AnyObject!) -> String? in

            if object is MWS_Album {
                return MWS_albumsKey
            }            
            return nil; // exclude from view
        } as YapDatabaseViewGroupingWithObjectBlock

        var sortingBlockType: YapDatabaseViewBlockType = YapDatabaseViewBlockTypeWithObject
        var sortingBlock = {
            (group: String!, collection1: String!, key1: String!, obj1: AnyObject!,
            collection2: String!, key2: String!, obj2: AnyObject!) -> NSComparisonResult in

            if obj1 is MWS_Album && obj2 is MWS_Album {
                var title1 = obj1.title as NSString
                var title2 = obj2.title as NSString
                return title1.caseInsensitiveCompare(title2)
            }
            return NSComparisonResult.OrderedSame
        } as YapDatabaseViewSortingWithObjectBlock 

       var yapDbView = YapDatabaseView(groupingBlock: groupingBlock, groupingBlockType: groupingBlockType, sortingBlock: sortingBlock, sortingBlockType: sortingBlockType)

        return yapDbView 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions