问题
This is the code we had in Swift 2. What is the Swift 3 version? I don't see a replacement for setShared.
let sharedCache: NSURLCache = NSURLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
NSURLCache.setSharedURLCache(sharedCache)
回答1:
This works in Xcode 8 Beta 4
URLCache.shared = sharedCache
回答2:
Here is an Example in Swift 3 increasing cache size to 500 MB
let memoryCapacity = 500 * 1024 * 1024
let diskCapacity = 500 * 1024 * 1024
let cache = URLCache(memoryCapacity: memoryCapacity, diskCapacity: diskCapacity, diskPath: "myDataPath")
URLCache.shared = cache
回答3:
It works for Xcode 8
URLCache.shared = {
URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
}()
来源:https://stackoverflow.com/questions/38249573/how-to-set-the-shared-urlcache-in-swift-3