Hi everyone ;-)
I work on an objc framework and we will modernize it by starting to implement new features in Swift. To do so, I'm currently writing a POC, but I encountered a weird crash.
If I just add some basic swift files and call them from my objc code, I can use my xcframework easily (from a swift app for the record). But, if the swift code contains Async/Await calls (even wrapped in a completion method), it does not work.
This code leads to a crash right away :
@objcMembers public class SwiftChecker: NSObject {
@available(iOS 13.0.0, *)
func check() async {
let data = try? await URLSession().data(for: URLRequest(url: URL(string: "http://www.google.fr")!))
if let data {
print("Yay! ❤️ \(data.0.count)")
} else {
print("Nay 😡")
}
}
public func check(completion: @escaping (() -> Void)) {
if #available(iOS 13.0.0, *) {
Task {
await check()
completion()
}
} else {
completion()
}
}
}
And I call it like that (inside the framework fyi) :
if (@available(iOS 13.0, *)) {
SwiftChecker* checker = [[SwiftChecker alloc] init];
[checker checkWithCompletion:^{
}];
}
I even tried a more simpler code with
@objcMembers public class SwiftChecker: NSObject {
@available(iOS 13.0.0, *)
func check() {
Task {
let data = try? await URLSession().data(for: URLRequest(url: URL(string: "http://www.google.fr")!))
if let data {
print("Yay! ❤️ \(data.0.count)")
} else {
print("Nay 😡")
}
}
}
}
but the result is the same.
I f I don't use Task
, then it works :-/
I can't find any reason or literature that indicates not to use modern concurrency with objC, especially when it's wrapped into a completion block like signature.
I just can't give you the crash log as it has nothing to do with the actual crash. It's just a exit with signal 6
Any help would be appreciated. Thanks!