当我的应用尝试使用以下代码取消归档cookie数据时,它总是崩溃。
if cookieData.length > 0 {
let cookies: [NSHTTPCookie] = NSKeyedUnarchiver.unarchiveObjectWithData(cookieData) as! [NSHTTPCookie]
for cookie: NSHTTPCookie in cookies {
NSHTTPCookieStorage.sharedHTTPCookieStorage().setCookie(cookie)
}
}
我收到以下错误:
Thread 1: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
你能告诉我如何修复这个错误吗?
答案 0 :(得分:0)
我自己解决了。以下代码确实有效:
if cookieData.length > 0 {
if let cookies: [NSHTTPCookie] = NSKeyedUnarchiver.unarchiveObjectWithData(cookieData) as? [NSHTTPCookie]{
for cookie: NSHTTPCookie in cookies {
NSHTTPCookieStorage.sharedHTTPCookieStorage().setCookie(cookie)
}
}
}