programing

여기서 발생하는 오류는 처리되지 않습니다.

lastcode 2023. 2. 9. 21:57
반응형

여기서 발생하는 오류는 처리되지 않습니다.

iOS 앱에서 JSON을 구문 분석하는 데 문제가 발생했습니다.

관련 코드:

let jsonData:NSDictionary = try JSONSerialization.jsonObject(with: urlData! as Data, options: JSONSerialization.ReadingOptions.mutableContainers ) as! NSDictionary

/* XCode error ^^^ Errors thrown from here are not handled */

누가 나 좀 도와줄래?

에러가 발생했을 가능성이 있습니다.let jsonData = try JSONSerialization ...처리되지 않습니다.

발생할 수 있는 오류를 무시하고 오류가 발생하면 패널티로 크래시할 수 있습니다.

let jsonData = try! JSONSerialization ...

또는 반환한다.Optional,그렇게jsonDatanil에러 케이스:

let jsonData = try? JSONSerialization ...

또는 발생한 오류를 포착하여 처리할 수 있습니다.

do {
    let jsonData = try JSONSerialization ...
    //all fine with jsonData here
} catch {
    //handle error
    print(error)
}

스위프트 언어를 공부하는 게 좋을 거야

언급URL : https://stackoverflow.com/questions/40470145/errors-thrown-from-here-are-not-handled

반응형