apollo-ios 如何在磁盘上缓存数据?

Ran*_*iys -3 ios swift graphql apollo-ios

我需要将我的数据缓存在磁盘上以供离线查看,我在 apollo-ios 源中找到了 ApolloSQLite,但是我找不到 ApolloSQLite 的任何文档(我也尝试过谷歌搜索)。

环境:

Xcode 10.1
macOS 10.14.3
CocoaPods 1.5.3

Apollo (0.9.5)
SQLite.swift (0.11.5)
Run Code Online (Sandbox Code Playgroud)

之后出现太多错误pod install

pod 'Apollo'
pod 'Apollo/SQLite'
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

Ran*_*iys 7

When I use CocoaPods 1.5.3, missing the source Apollo/Core after pod install, it causes the errors. I've fixed it by upgrade CocoaPods to 1.6.0.

BTW, the original question is how to use ApolloSQLite? Because I've not found any documents for ApolloSQLite. After too many search & query, I list my steps as below for other people for help:

  1. use CocoaPods for manage the libs:
pod 'Apollo'
pod 'Apollo/SQLite'
Run Code Online (Sandbox Code Playgroud)
  1. need a file path to save the sqlite file which use for cache data. Paste my codes for refer:

    func temporarySQLiteFileURL() -> URL {
        let applicationSupportPath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first!
        let dbPath = applicationSupportPath + "/com.[special name].cache"
    
        if !FileManager.default.fileExists(atPath: dbPath) {
            try? FileManager.default.createDirectory(atPath: dbPath, withIntermediateDirectories: true, attributes: nil)
        }
    
        let url = URL(fileURLWithPath: dbPath)
        return url.appendingPathComponent("db.sqlite3")
    }
    
    Run Code Online (Sandbox Code Playgroud)
  2. configure the ApolloClient:

        let configuration = URLSessionConfiguration.default
        configuration.timeoutIntervalForRequest = 10
    
        let url = URL(string: self.graphQLApiAddress!)!
        let networkTransport = HTTPNetworkTransport(url: url, configuration: configuration)
    
        let cache = try? SQLiteNormalizedCache(fileURL: temporarySQLiteFileURL())
        let store = ApolloStore(cache: cache ?? InMemoryNormalizedCache())
        self.apolloClient = ApolloClient(networkTransport: networkTransport, store: store)
    
    Run Code Online (Sandbox Code Playgroud)