如何从YapDatabase视图获取对象?

时间:2018-10-02 15:41:27

标签: swift view yapdatabase

强烈建议我在Swift 4中使用YapDatabase。我对Swift和Yap都是新手。通过阅读与YapDatabase相关的大量Wiki,我了解到我应该创建数据视图,然后将其呈现在UI中。我试图避免的是将数据存储直接耦合到UI,这正是所有示例都在做的事情。为此,我实际上认为封装数据存储并通过RxSwift 公开其内容是一种不错的方法,并且我对此表示赞赏。现在,我只是尝试获取视图的内容。到目前为止,我已经有了以下代码来创建一组属性:

// Class level variables configured at init()

_database = YapDatabase(path: path)!
_readConnection = _database.newConnection()
_readConnection.metadataCacheEnabled = false
_readConnection.objectCacheLimit = 400

func createPropertiesGrouping()
{
    let grouping =
        YapDatabaseViewGrouping.withObjectBlock({ (readTransaction, str1, str2, object) -> String? in
            if ( object is Property )
            { return "properties" }
            return nil
        })

    let sorting = YapDatabaseViewSorting.withObjectBlock { (readTransaction, str1, str2, str3, object1, str4, str5, object2) -> ComparisonResult in
        return .orderedSame
    }

    let propertyView = YapDatabaseAutoView(grouping: grouping, sorting: sorting)
    _database.asyncRegister(propertyView, withName: "properties")
}

我已经在我的数据存储类的'init'方法中初始化了一个只读连接,如下所示:

_readConnection.enableExceptionsForImplicitlyEndingLongLivedReadTransaction()
_readConnection.beginLongLivedReadTransaction()

但是我到底如何才能将视图的内容取回来?我实际上认为YapDatabaseAutoView在这里是错误的选择,但是文档显示了使用类YapDatabaseView的Objective-C变体,它对我来说似乎是抽象的。

我很感谢任何有关如何获取视图内容的指针,以便以后可以在RxSwift中使用它。

0 个答案:

没有答案