2016-12-06 87 views
1

這裏是我的代碼NSMutableURLRequest的CachePolicy不工作

let url = NSURL(string: user_url) 
    var request = NSMutableURLRequest.init(URL: url!, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: 5) 

我得到這個錯誤:

Type 'NSURLRequestCachePolicy' has no member 'reloadIgnoringLocalCacheData'

我把這個constant from the docs所以我想知道我要去的地方錯在這裏?

這是SWIFT 2.3(不太多的選擇/決定)+的XCode 8.

+0

您定位的是Xcode和Swift的哪些版本? –

+0

@JimMatthews添加細節問題。 – helloB

回答

2

爲SWIFT 2.x的你想要:

let url = NSURL(string: user_url) 
var request = NSMutableURLRequest.init(URL: url!, cachePolicy: .ReloadIgnoringLocalCacheData, timeoutInterval: 5) 

ReloadIgnoringLocalCacheData was re作爲偉大的Swift 3重命名的一部分命名爲reloadIgnoringLocalCacheData,因此是文檔。要找出編譯器正在查找的內容,請通過命令單擊方法調用,然後單擊參數類型(NSURLRequestCachePolicy) - 這會將您帶到編譯器實際使用的聲明。

0

嘗試這種情況:

編輯(夫特2)

NSMutableURLRequest(url: url!, cachePolicy: .ReloadIgnoringLocalCacheData, timeoutInterval: 4) 
+0

我看到使用未解析的標識符'MutableURLRequest',當我嘗試這個。 – helloB

+0

您必須使用Swift2。如果是這樣,請使用大寫字母。像ReloadIgnoringLocalCacheData一樣。 – Ryan