2016-07-01 2 views
1

저는 신속하고 날씨 응용 프로그램을 만드는 데 매우 익숙합니다. 프로토콜이 func weatherManagerFailedToLoadCityWithError(error: ErrorType)입니다. weatherManager.swift에서이 코드 블록날씨 응용 프로그램의 오류 유형 프로토콜

func weatherManagerFailedToLoadCityWithError(error: ErrorType) { 

} 

어떤 제안에 weatherController.swift 어떻게해야합니까 일부 위임

} else if status == 404 { 
       // City not found 
       if self.delegate != nil { 
        dispatch_async(dispatch_get_main_queue(), {() -> Void in 
         self.delegate?.weatherManagerFailerToLoadCityWithError(.InvalidResponse) 
        }) 
       } 

      } else { 
       // Some other here? 
       if self.delegate != nil { 
        dispatch_async(dispatch_get_main_queue(), {() -> Void in 
         self.delegate?.weatherManagerFailerToLoadCityWithError(.MissingData) 
        }) 
       } 
      } 

있나요? 다음 함수를 호출

private struct ErrorInformation { 
    static let Domain = "us.firmaName" 
    static let ServerNotFoundDomain = "\(ErrorInformation.Domain).notFound" 
} 

private extension NSError { 
    static func serverNotFound() -> NSError { 
     let userInfo = [ 
      NSLocalizedDescriptionKey: NSLocalizedString("Server Not Found", comment: ""), 
      NSLocalizedFailureReasonErrorKey: NSLocalizedString("The Server you are asking for is not available.", comment: ""), 
      NSLocalizedRecoverySuggestionErrorKey: NSLocalizedString("Please proof your URL bla-bla-bla.", comment: "") 
     ] 

    return NSError(domain: ErrorInformation.ServerNotFoundDomain, code: 404, userInfo: userInfo) 
} 

을 그리고 :

답변

0

이 같은 그것을 할 수

당신이 당신의 함수에서 오류를 처리 할 수 ​​원하는 경우
weatherManagerFailedToLoadCityWithError(error: NSError.serverNotFound()) 

:

func weatherManagerFailedToLoadCityWithError(error: ErrorType) { 
    print("Error description: \(error.userInfo. NSLocalizedDescriptionKey)") 
} 

더 많은 설명이 필요하면 더 많은 코드를 게시하십시오.