【问题标题】:partial apply for thunk Crash.部分申请thunk Crash。
【发布时间】:2016-05-29 02:53:13
【问题描述】:

无法理解 Crashlytics 中的崩溃报告。

这是崩溃日志:

Crashed: com.apple.main-thread
0  Rekindlr                       0x10007a728 ViewController.(user_info(Match?, completionHandler : (Bool?) -> ()) -> ()).(closure #1) (ViewController.swift:201)
1  Alamofire                      0x100156678 partial apply for thunk (ResponseSerialization.swift)
2  Alamofire                      0x10015891c specialized Request.(response<A where ...> (queue : OS_dispatch_queue?, responseSerializer : A, completionHandler : (Response<A.SerializedObject, A.ErrorObject>) -> ()) -> Self).(closure #1).(closure #1) (ResponseSerialization.swift:131)
3  libdispatch.dylib              0x1827614bc _dispatch_call_block_and_release + 24
4  libdispatch.dylib              0x18276147c _dispatch_client_callout + 16
5  libdispatch.dylib              0x182766b84 _dispatch_main_queue_callback_4CF + 1844
6  CoreFoundation                 0x182cccdd8 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
7  CoreFoundation                 0x182ccac40 __CFRunLoopRun + 1628
8  CoreFoundation                 0x182bf4d10 CFRunLoopRunSpecific + 384
9  GraphicsServices               0x1844dc088 GSEventRunModal + 180
10 UIKit                          0x187ec9f70 UIApplicationMain + 204
11 Rekindlr                       0x10007d4e4 main (AppDelegate.swift:17)
12 libdispatch.dylib              0x1827928b8 (Missing)

及相关来源:

typealias CompletionHandler = (success: Bool) -> Void


func user_info(match:(Match?), completionHandler:CompletionHandler) {
    var tind_id = match!.tinder_id
    var user_url = "\(USER_INFO_URL)\(tind_id)"
    Alamofire.request(.GET, user_url, headers: ["X-Auth-Token": tinder_token], encoding: .JSON)
        .responseJSON { response in

            let json = JSON(response.result.value!)

            var result = json["results"]
            var distance = result["distance_mi"].intValue

            let realm = try! Realm()

            try! realm.write {
                match?.distance_km = round(Double(distance) / 0.62137)
            }

            completionHandler(success: true)
    }
}

我猜我在使用completionHandler 的方式上做错了什么?但它不会发生在每个人身上。我无法重现崩溃,但我的一些用户得到了它。

【问题讨论】:

  • 直接的嫌疑人是感叹号。在第 10 行确保该值不为空
  • 我同意@UriBrecher。你说try! 两次。这意味着“请让我崩溃”。当 Swift 完成你要求它做的事情时,你几乎不会感到惊讶。

标签: swift alamofire completionhandler


【解决方案1】:

同意@Uri 和@matt - 如果您不知道 do/catch 语法,那么应该如何实现这些行:

do {
  let realm = try Realm()
  try realm.write {
    match?.distance_km = round(Double(distance) / 0.62137)
  }
}catch {
  print(error)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-30
    • 1970-01-01
    • 2017-05-03
    • 1970-01-01
    相关资源
    最近更新 更多