斯威夫特 - 1.2,解析 - 1.7.4,缓存策略

Posted

技术标签:

【中文标题】斯威夫特 - 1.2,解析 - 1.7.4,缓存策略【英文标题】:Swift - 1.2, Parse - 1.7.4, CachePolicy 【发布时间】:2015-06-29 20:28:46 【问题描述】:

我正在尝试从 Parse 数据库中检索查询;但是,当我运行应用程序并单击按钮转到将从数据库中检索数据的视图控制器时,我的应用程序崩溃了。当应用程序崩溃时,我会收到 AppDelegate.swift 文件。

这是错误:由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“启用固定时不允许方法。”

我确保在我的项目中正确实施 Parse。此外,当我取出 if self.objects.count == 0 代码块时,当我转到从数据库中检索数据的视图控制器时,应用程序运行良好。但只有这一次,当我的解析数据库中有对象时,我的 tableview 列表中没有对象。提前致谢。

override func queryForTable() -> PFQuery 
    let query = PFUser.query()

    if searchInProgress 
        // We are looking for the string contents in the search bar to match the names in the parse username category.
        query?.whereKey("username", containsString: searchString)
    

    // From the objects aleady loaded...
    if self.objects?.count == 0
        // If we have not already loaded the elements from our database, then it will use the elements that have already been downloaded when we have already run the app
        query?.cachePolicy = PFCachePolicy.CacheThenNetwork
    

    query?.orderByAscending("username")
    return query!

【问题讨论】:

【参考方案1】:

您不能同时使用固定和缓存策略,因此会出现不一致异常。 http://parse.com/docs/ios/api/Classes/PFQuery.html#//api/name/cachePolicy

【讨论】:

以上是关于斯威夫特 - 1.2,解析 - 1.7.4,缓存策略的主要内容,如果未能解决你的问题,请参考以下文章

模板方法模式-缓存淘汰策略有哪些?

如何将数组对象转换为 JSON 字符串。 IOS 8。斯威夫特 1.2

HTTP协议的缓存策略有哪些?

HTTP协议的缓存策略有哪些?

Redis与Mysql双写一致性方案解析

缓存的淘汰策略有几种?分别怎么用?