Open ahlager opened 2 years ago
session.delegateQueue.async { fetch?.start ({ *** }) }
@ahlager I'm running into this same issue. Did you ever find a fix?
@imotoboy Can you elaboriate on that? Is session
supposed to be an MCOIMAPSession
object?
@cliftonlabrum unfortunately no, this didn't work and I was not able to find a fix.
This is a problem with XCode and mailcore works well. You cannot execute step by step as these lines go onto a different thread onto a different processor (and debugger is not able to return values properly). SOLUTION:
NOTE (XCode not always translates properly to async) For fetch messages you might need to write async extension (the below code works, and returns empty list or list of values):
extension MCOIMAPFetchMessagesOperation { func fetchMessages() async throws -> [Any] { typealias PostContinuation = CheckedContinuation <[Any], Error> return try await withCheckedThrowingContinuation { (continuation:PostContinuation) in self.start { (error: Error?, headers: [Any]?, indexSet: MCOIndexSet?) -> Void in if let error = error { print("Error downloading message UIDs: (error)") let mHeaders:[Any] = [] continuation.resume(returning: mHeaders) } else { print("Successful IMAP messages headers download") var mHeaders:[Any] = [] if (headers != nil) {mHeaders = headers!} continuation.resume(returning: mHeaders) }}}}
Hello, using the latest await/async paradigm in Swift I'm running into an error.
When calling
fetchMessagesOperation
with .start() async inside an async function, I get an error of:0: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value
. No matter if I have guards, checks, it will always hard crash.However, running the same code but with the non-async version of .start(), it does not crash.
I have tested with other "fetch" functions/operations and I do not see the same results. Only with async
fetchMessagesOperation
.Below is the code I'm using
ASYNC: This is the code that crashes
NON-ASYNC: This does not crash
Additionally, using the
connectionlogger
, the output data for each is exactly the same: