I was exploring the async/await feature using the March 25th development snapshot to call an API with URLSession where I got the following crash and I was not able to figure out what's causing this
I tried couple of things but was not able to resolve this, given below is my code for calling the API
func testFunction() async -> [Project]?
{
var urlRequest = URLRequest(url: URL(string: "MY_API")!)
urlRequest.httpMethod = "get"
return await withUnsafeContinuation { continuation in
let task = URLSession.shared.dataTask(with: urlRequest) { data, response, error in
if(error == nil && data != nil && data?.count != 0) {
do {
let decoder = JSONDecoder()
// for date formatting
decoder.dateDecodingStrategy = .iso8601
let result = try decoder.decode([Project].self, from: data!)
continuation.resume(returning: result)
} catch {
debugPrint(error.localizedDescription)
}
}
}
task.resume()
}
}
and I have a separate structure with a function having the @asyncHandler attribute where I am calling this async function
struct SyncResource
{
@asyncHandler func syncDataResources()
{
let projectObj = ProjectDataResource()
let projects = await projectObj.testFunction()
}
and in the viewDidLoad function of the viewController I am creating the object of the SyncResource struct and calling the syncDataResource function where I encountered the above crash, anyone else facing the same issue, or am I doing something wrong here?
I am not getting any compile or build errors I even added the concurrency flag as mentioned in the proposal