2016-11-08 92 views
0

我正在使用xcode 7.3和swift 2.3。爲了建立網絡連接,我使用'Alamofire','〜> 3.4.1'。直到我執行歸檔選項時,我纔會遇到問題。我正在和Xcode的標記在--->標記這個錯誤由於信號命令失敗:分段錯誤:11:alamofire post

命令失敗,原因是信號:分段故障:11

class func post(url: String, headers:[String: String], parameters:[String: AnyObject], success:(AnyObject)->(), failure:(AnyObject)->()) ->() { 
--->  Alamofire.request(.POST, 
      url, 
      headers:headers, 
      parameters:parameters,encoding:.URL) 
      .debugLog() 
      .validate(statusCode: 200..<300) 
      .responseString { response in 

       response.debugLog() 
       switch response.result{ 
       case .Success(_): 
        //print(response) 
        let httpResponseBody = response.result.value! as String 
        success(httpResponseBody) 

       case .Failure(_): 
        let error = response.result.error 
        //print(error) 
        failure(error!) 


       } 
     } 

回答

0

浪費4小時調試錯誤的原因後,我終於身影這段代碼導致了問題。

extension Request { public func debugLog() -> Self { //#if DEBUG debugPrint(self) //#endif return self } }

然後我從

class func post(url: String, headers:[String: String], parameters:[String: AnyObject], success:(AnyObject)->(), failure:(AnyObject)->()) ->() { 
--->  Alamofire.request(.POST, 
      url, 
      headers:headers, 
      parameters:parameters,encoding:.URL) 
      // .debugLog() 
      .validate(statusCode: 200..<300) 
      .responseString { response in 

       response.debugLog() 
       switch response.result{ 
       case .Success(_): 
        //print(response) 
        let httpResponseBody = response.result.value! as String 
        success(httpResponseBody) 

       case .Failure(_): 
        let error = response.result.error 
        //print(error) 
        failure(error!) 


       } 
     } 
註釋的.debug()
相關問題