Skip to content

[Technical Questions] Sending ‘self’ risks causing data races in MFMailComposeViewControllerDelegate #168

Discussion options

You must be logged in to vote

Hi @jennleww, you should be able to fix this problem by calling your completion handler from the main thread with a weak capture of self, like this

    func mailComposeController(_ controller: MFMailComposeViewController,
                               didFinishWith result: MFMailComposeResult,
                               error: Error?) {
        // Explicitly dispatch UI updates to the main thread
        DispatchQueue.main.async { [weak self] in
            guard let self else { return }
            self.parent.completion?(result)
            controller.dismiss(animated: true)
        }
    }

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nriedman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants