use*_*037 5 nserror ios swift cloudkit ckerror
CKError在应用程序中向用户显示遇到的警报.注意:此问题与要显示的UI代码无关.只想从错误中提取有意义的字符串.
我尝试使用localizedDescription但它似乎没有包含适当的字符串
以下是我的尝试:
po error
<CKError 0x1c464cea0: "Network Unavailable" (3/NSURLErrorDomain:-1009); "The Internet connection appears to be offline.">
po error.localizedDescription
"The operation couldn’t be completed. (CKErrorDomain error 3.)"
po (error as! CKError).errorUserInfo
? 2 elements
? 0 : 2 elements
- key : "NSUnderlyingError"
- value : Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={NSErrorFailingURLStringKey=https:/
? 1 : 2 elements
- key : "NSDebugDescription"
- value : NSURLErrorDomain: -1009
po (error as? NSError)?.localizedFailureReason
nil
po (error as? NSError)?.localizedRecoverySuggestion
nil
po (error as? NSError)?.localizedRecoveryOptions
nil
po (error as? NSError)?.debugDescription
? Optional<String>
- some : "<CKError 0x1c064eaf0: \"Network Unavailable\" (3/NSURLErrorDomain:-1009); \"The Internet connection appears to be offline.\">"
Run Code Online (Sandbox Code Playgroud)
调试描述似乎最接近我想要的.
看起来 errorUserInfo[NSUnderlyingError] 中还有另一个错误。尝试从该错误中获取 localizedDescription。
所以,那将是:
((error as? CKError)?.errorUserInfo[NSUnderlyingErrorKey] as? NSError)?.localizedDescription
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
425 次 |
| 最近记录: |