2
我正在嘗試將this class從Objective-C轉換爲Swift。我除了這個方法幾乎做到了:如何將此方法從Objective-C轉換爲Swift
-(void) handleCookiesInRequest:(NSMutableURLRequest*) request
{
NSURL* url = request.URL;
NSArray* cookies = [self cookiesForURL:url];
NSDictionary* headers = [NSHTTPCookie requestHeaderFieldsWithCookies:cookies];
NSUInteger count = [headers count];
__unsafe_unretained id keys[count], values[count];
[headers getObjects:values andKeys:keys];
for (NSUInteger i=0;i<count;i++) {
[request setValue:values[i] forHTTPHeaderField:keys[i]];
}
}
我嘗試:
func handleCookiesInRequest(request: NSMutableURLRequest) {
var url = request.URL
var cookies = self.cookiesForURL(url!)
var headers = NSHTTPCookie.requestHeaderFieldsWithCookies(cookies)
var count = headers.count
for i in 0...count {
request.setValue(value: headers.values[i], forHTTPHeaderField: headers.keys[i])
}
}
我得到了說
CustomHTTPCookieStorage.swift:88:21: Type '(value: $T8, forHTTPHeaderField: $T21)' does not conform to protocol '_SignedIntegerType'
你能幫我設定值行的錯誤?
'value'的值是多少? – Fogmeister 2015-02-23 15:15:41
對不起。我做了一個錯誤的方法。我剛剛更新了它。你能重新檢查嗎? – 2015-02-23 15:26:13
這是我不明白的部分:__unsafe_unretained id鍵[count],values [count]; – 2015-02-23 15:26:45