It seems like URLSession.data async function is available under iOS 13.. Is this intended or a bug?
AFAIK Swift concurrency was backported to iOS 13 so apparently so were the extensions to URLSession and other APIs.
Yes, there are two sets of async
APIs on URLSession
. There are those that you're seeing, which are just automatically adapted versions of the completion handler APIs into async
, and the newer async
APIs which take a delegate
parameter. Those newer APIs are only available on newer OS versions.
Got it, thank you for confirming
بہتر ہے، URLSession.data فاؤنڈیشن اےپ آئی او ایس 13 میں دستیاب ہے۔ URLSession فاؤنڈیشن فریم ورک کا حصہ ہے جو نیٹ ورک ڈیٹا منتقلی کے مسائل کو حل کرنے کے لئے ای پی آئی فراہم کرتا ہے۔ "URLSession.data" کے ذریعہ ڈیٹا ٹاسک کو بنانے سے آپ ایک URL کی مواد کو ڈیٹا آبجیکٹ کے طور پر حاصل کرنے کے لئے استعمال کرسکتے ہیں۔ یہ iOS 7 میں متعارف کروایا گیا تھا اور تمام بعدی iOS نسخوں میں دستیاب تھا، اس میں iOS 13 شامل ہے۔
نیچے ایک مثال دی گئی ہے جو دکھاتی ہے کہ URLSession.data کا استعمال کرنے کے لئے ایک بنیادی GET درخواست کیسے کی جائے:
import UIKit
func fetchDataFromURL() {
guard let url = URL(string: "https://api.example.com/data") else {
print("Invalid URL")
return
}
let session = URLSession.shared
let dataTask = session.dataTask(with: url) { (data, response, error) in
if let error = error {
print("Error: \(error)")
return
}
guard let data = data else {
print("No data received")
return
}
// یہاں ڈیٹا کو پروسیس کریں
print("Received data: \(data)")
}
dataTask.resume()
}
یاد رہے کہ حقائق کو مناسب طریقے سے ہینڈل کریں اور استعمال کرنے والے اطلاقات میں URLSession.data کے استعمال کرتے ہوئے مین تھریڈ پر یو آئی اپ ڈیٹس کریں۔