2015-09-03 62 views
0

Crashlytics報道與消息多個崩潰:iOS應用崩潰由於「功能簽名專業化<精氨酸[0] =分解精氨酸[2] =分解>」

function signature specialization <Arg[0] = Exploded, Arg[2] = Exploded> 

是什麼異常意味着在第一名?

這裏是我的代碼,崩潰報告在閉包內的「return resultSoFar」中。

private class func reduceMemberships(memberships: [HappeningMember]) -> (map: Dictionary<String, HappeningMember>, maxDateAsString: String?) { 
    let maxDateAsString = Session.lastUpdatedAt 
    let maxDateAsDouble = (maxDateAsString == nil) ? 0 : DateUtil.localDateFromIsoDateString(maxDateAsString!)!.timeIntervalSince1970 
    let initialTuple = (map: Dictionary<String, HappeningMember>(), maxDateAsString: maxDateAsString, maxDateAsDouble: maxDateAsDouble) 
    let reductionResult = memberships.reduce(initialTuple) { 
     (var resultSoFar, membership) in 
     let membershipUpdatedAtAsAdouble = DateUtil.localDateFromIsoDateString(membership.updatedAt)!.timeIntervalSince1970 
     resultSoFar.map[membership.happening._id] = membership 
     resultSoFar.maxDateAsDouble = max(membershipUpdatedAtAsAdouble, resultSoFar.maxDateAsDouble) 
     resultSoFar.maxDateAsString = (resultSoFar.maxDateAsDouble == membershipUpdatedAtAsAdouble) ? membership.updatedAt : resultSoFar.maxDateAsString 
     return resultSoFar // CRASHES HERE 
    } 
    return (reductionResult.map, reductionResult.maxDateAsString) 
} 

回答

1

我懷疑這是因爲你是從一個完成處理程序返回。嘗試使用完成處理程序而不是返回,這將與此函數的異步方式一起工作。

private class func reduceMemberships(memberships: [HappeningMember], completion: (map: Dictionary<String, HappeningMember>, maxDateAsString: String?)) { 
    let maxDateAsString = Session.lastUpdatedAt 
    let maxDateAsDouble = (maxDateAsString == nil) ? 0 : DateUtil.localDateFromIsoDateString(maxDateAsString!)!.timeIntervalSince1970 
    let initialTuple = (map: Dictionary<String, HappeningMember>(), maxDateAsString: maxDateAsString, maxDateAsDouble: maxDateAsDouble) 
    let reductionResult = memberships.reduce(initialTuple) { 
     (var resultSoFar, membership) in 
     let membershipUpdatedAtAsAdouble = DateUtil.localDateFromIsoDateString(membership.updatedAt)!.timeIntervalSince1970 
      resultSoFar.map[membership.happening._id] = membership 
      resultSoFar.maxDateAsDouble = max(membershipUpdatedAtAsAdouble, resultSoFar.maxDateAsDouble) 
      resultSoFar.maxDateAsString = (resultSoFar.maxDateAsDouble == membershipUpdatedAtAsAdouble) ? membership.updatedAt : resultSoFar.maxDateAsString 
     completion(map: resultSoFar.map, maxDateAsString: resultSoFar.maxDateAsString ) 
    } 
    completion(map: reductionResult.map, maxDateAsString: reductionResult.maxDateAsString) 
} 
+0

感謝您的回答,但從完成處理程序返回時出現了什麼問題?我在遊樂場試過了,它按預期工作(返回版本)。 – Abdurrahman

+0

問題是完成處理程序是異步的,這意味着完成處理程序在該函數完成後執行。所以你不能從函數完成後運行的代碼中返回一些東西。因此您需要使用完成處理程序 – Swinny89