如何在swift 3中设置共享URLCache?

时间:2016-07-07 15:31:24

标签: swift3 nsurlcache

这是我们在Swift 2中的代码。什么是Swift 3版本?我没有看到setShared的替代品。

let sharedCache: NSURLCache = NSURLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
NSURLCache.setSharedURLCache(sharedCache)

3 个答案:

答案 0 :(得分:26)

这适用于Xcode 8 Beta 4

const async     = require("async");
const uuid      = require("node-uuid");
const request   = require('request');

const apiai = require('apiai');
const express = require('express');
const bodyParser = require('body-parser');
const JSONbig = require('json-bigint');

答案 1 :(得分:11)

以下是Swift 3中将缓存大小增加到500 MB的示例

    let memoryCapacity = 500 * 1024 * 1024
    let diskCapacity = 500 * 1024 * 1024
    let cache = URLCache(memoryCapacity: memoryCapacity, diskCapacity: diskCapacity, diskPath: "myDataPath")
    URLCache.shared = cache

答案 2 :(得分:3)

适用于Xcode 8

URLCache.shared = {
        URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
}()