swift Error 모음. Xcode, iOS 에러 모음 누적

|

Xcode에서 발생하는 각종 에러를 간단하게 하나하나 정리해보렵니다.

1. function is not declared ‘throws

Error:

Error is not handled because the enclosing function is not declared 'throws'

code:

guard let url = URL(string: API)?.appendingPathComponent(endpoint)  else {
  throw EOError.invalidURL(endpoint)
  //url변경등등의 사유로 에러 날 때 throw하고자 함.
}

Solution:

do catch로 감싸야 한다.

do{
  guard let url = URL(string: API)?.appendingPathComponent(endpoint)  else {
    throw EOError.invalidURL(endpoint)
    //url변경등등의 사유로 에러 날 때
  }
	.
	.
catch {
      return Observable.empty()
}

Comments