throws
선언에 유형이 필요한 Java와 달리 Swift에서는 알 수없는 어떤 유형의 Error
이 던져 질 것입니다. 당신이 알고있는 유일한 것은 객체가 Error
- 프로토콜을 따르고 있다는 것입니다.
기능이 잘 문서화 되었기 때문에 Error
이라는 특수 문자가 포함 된 경우 캐치 된 객체를 올바르게 캐스팅해야합니다.
예 : 당신은 구글에 대한 질문입니다
do {
try moveItem(from: someUrl, to: otherUrl)
} catch {
//there will automatically be a local variable called "error" in this block
// let's assume, the function throws a MoveItemError (such information should be in the documentation)
if error is MoveItemError {
let moveError = error as! MoveItemError //since you've already checked that error is an MoveItemError, you can force-cast
} else {
//some other error. Without casting it, you can only use the properties and functions declared in the "Error"-protocol
}
}
을 생각하지 않는다? –
나는 시험해 보았다. 그러나 나는 대답을 얻지 못했습니다. 어쩌면 핵심어를 알아 내지 못했을 수도 있습니다. – Matt