I use await MainActor.run { main thread stuff } instead of DispatchQueue.main.async when I am in an async func. Is this comparable to Task { @MainActor in main thread stuff }, which is really new to me, or are there differences?
Post
Replies
Boosts
Views
Activity
Are you storing your project files in iCloud Drive maybe? And use Xcode also on another Mac?
That may be the cause of duplicate files with suffix 2, iCloud not working 100% all of the time?
I have exactly the same experience, using Xcode 12.5 and an iPhone 7 with iOS 14.4.2.
Did not yet find a solution or workaround...
Anyone tried it with 14.6 yet?
I am working on scanning a MiFare tag and reading the EEPROM (NDEF) and SRAM part by sending mifareTag.sendMiFareCommands. This works very well in a test app where I just feed static commands from an array to the tag, but gives a lot of problems (Tag connection lost or responseBlocks not giving back results or ACK's), when giving exactly the same commands from an app where all command parameters are calculated. What (probably...) solved it for me was defining mij own serial queue:let tagScanQueue = DispatchQueue(label: "xxxxxxxx.tagScanQueue", qos: .userInitiated)tagReaderSession = NFCTagReaderSession(pollingOption: .iso14443, delegate: self, queue: tagScanQueue)and wrapping every function calling my mifareTag.sendMiFareCommands function in tagScanQueue.asyncAfter: private func sendCommandXxxxxx(to mifareTag: NFCMiFareTag) {
tagScanQueue.async {
self.sendCommand(xxxxxx, to: mifareTag) {
result in
...
}
}
} private func sendCommand(_ mfCommand: MFCommandContent, to mifareTag: NFCMiFareTag,
returnResult: @escaping (Data) -> Void) {
tagScanQueue.asyncAfter(deadline: .now() + .milliseconds(mfCommand.delay)) {
mifareTag.sendMiFareCommand(commandPacket: mfCommand.command) {
responseBlock, error in
if let error = error {
self.invalidateScan(.tagInvalid(messageCode: 123)) // MiFare command gives an error
return
}
guard responseBlock.count != 1 ||
responseBlock == Data([0x0A]) else {
self.invalidateScan(.tagInvalid(messageCode: 456)) // MiFare command gives an invalid response
return
}
returnResult(responseBlock)
}
}
}Maybe this helps you?