спасибо за @escaping @callee_guaranteed (@guaranteed UIAlertAction) -> () - PullRequest
1 голос
/ 25 апреля 2020

Я следую за cra sh, который происходит в живом приложении, я не могу воспроизвести его во время разработки. Бревно от Crashlytics.

Я не могу понять причину cra sh и как исправить.

Любая помощь?

Cra sh Журнал

Crashed: com.apple.main-thread
0  MyApp                          0x100f5d538 closure #2 in MyViewController.buttonTapped(_:) + 4308292920 (<compiler-generated>:4308292920)
1  MyApp                          0x101250a98 thunk for @escaping @callee_guaranteed (@guaranteed UIAlertAction) -> () + 4311386776 (<compiler-generated>:4311386776)
2  UIKitCore                      0x19cb4aed0 -[UIAlertController _invokeHandlersForAction:] + 108
3  UIKitCore                      0x19cb4b82c __103-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:dismissCompletion:]_block_invoke.458 + 28
4  UIKitCore                      0x19cdfcfe0 -[UIPresentationController transitionDidFinish:] + 952
5  UIKitCore                      0x19ce0176c __56-[UIPresentationController runTransitionForCurrentState]_block_invoke.503 + 208
6  UIKitCore                      0x19cf055a8 -[_UIViewControllerTransitionContext completeTransition:] + 100
7  UIKitCore                      0x19d981d90 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 588
8  UIKitCore                      0x19d955c70 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 244
9  UIKitCore                      0x19d956178 -[UIViewAnimationState animationDidStop:finished:] + 240
10 UIKitCore                      0x19d9562c8 -[UIViewAnimationState animationDidStop:finished:] + 576
11 QuartzCore                     0x19ff07dac CA::Layer::run_animation_callbacks(void*) + 276
12 libdispatch.dylib              0x19913f184 _dispatch_client_callout + 16
13 libdispatch.dylib              0x1990f1190 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1044
14 CoreFoundation                 0x1993f05e4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
15 CoreFoundation                 0x1993eb5d8 __CFRunLoopRun + 2004
16 CoreFoundation                 0x1993eaadc CFRunLoopRunSpecific + 464
17 GraphicsServices               0x1a338b328 GSEventRunModal + 104
18 UIKitCore                      0x19d4f863c UIApplicationMain + 1936
19 MyApp                          0x100f24840 main + 21 (ProfileViewController.swift:21)
20 libdyld.dylib                  0x199274360 start + 4

MyViewController.swift

@IBAction func buttonTapped(_ sender: UIButton) {

    let alert = UIAlertController(title: "Delete", message: "", preferredStyle: .alert)

    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel) { (action) in
        return
    }

    let deleteAction = UIAlertAction(title: "Delete", style: UIAlertAction.Style.default) { (action) in
        let indexPathRow = sender.tag

        guard indexPathRow >= 0 else {
            return
        }

        guard let id = self.dataSource[indexPathRow].id else {
            return
        }
        self.delete(id: id)
    }

    alert.addAction(cancelAction)
    alert.addAction(deleteAction)

    DispatchQueue.main.async {
        self.present(alert, animated: true, completion: nil)
    }
}

1 Ответ

1 голос
/ 25 апреля 2020

Попробуйте следующее

@IBAction func buttonTapped(_ sender: UIButton) {

    let alert = UIAlertController(title: "Delete", message: "", preferredStyle: .alert)

    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertAction.Style.cancel) { (action) in
        return
    }

    // prepare data on stack call
    let indexPathRow = sender.tag
    guard indexPathRow >= 0 else { return }
    guard let id = self.dataSource[indexPathRow].id else { return }

    let deleteAction = UIAlertAction(title: "Delete", 
            style: UIAlertAction.Style.default) { [weak self] (action) in
        self?.delete(id: id)
    }

    alert.addAction(cancelAction)
    alert.addAction(deleteAction)

    DispatchQueue.main.async { [weak self] in
        self?.present(alert, animated: true, completion: nil)
    }
}
...