Use Async Await with MVVM and URLSession (JSON API Calls ) | Swift Concurrency Hindi 2024 | Xcode 15

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 มิ.ย. 2023
  • In this video, you will learn about Swift concurrency feature, Async Await, MainActor, Task and explore how it can be seamlessly integrated with the MVVM architecture and URLSession. Join us as we unlock the full potential of Swift Concurrency and learn how to write efficient, responsive, and scalable code. Stay ahead of the curve and elevate your Swift development skills in 2024!
    📕 Github Project:
    Download Project - github.com/YogeshPateliOS/Asy...
    📹 TH-cam Videos:
    MVVM With API: • Part 1 - MVVM (Model V...
    📱 My Applications:
    G1 Driving Test - Ontario 2023
    apps.apple.com/ca/app/g1-driv...
    My Music - Play & Share
    apps.apple.com/us/app/my-musi...
    BMI Weight Loss Calculator
    apps.apple.com/us/app/bmi-wei...
    🙋‍♂️ Say Hi on Social Media:
    Linkedin: / yogeshpatelios
    Instagram: / codewithyogesh
    By Me A Coffee: www.buymeacoffee.com/yogeshpa...
    If you enjoyed this project and found it useful, please share and recommend it so others can find it 💚💚💚💚💚💚 !!!!
    / yogeshpatelios - Please Like, Subscribe and share if it found useful for you 🤟
    Enjoy!!! 😀

ความคิดเห็น • 45

  • @AnkitaJaiswal-v9f
    @AnkitaJaiswal-v9f หลายเดือนก่อน +1

    Very nicely explained. Thankyou :)

  • @SauravSagar-rj8mp
    @SauravSagar-rj8mp 4 หลายเดือนก่อน +1

    Thankyou Yogesh bhai awesome hai ye..

  • @parthbarot-nc8mr
    @parthbarot-nc8mr 9 หลายเดือนก่อน +1

    Very detailed explanation...!! Thanks for sharing...

  • @AmitBiswastunebox
    @AmitBiswastunebox 7 วันที่ผ่านมา +1

    Bro could you please create a video about advanced debugging techniques.

  • @vishalbavaliya5788
    @vishalbavaliya5788 11 หลายเดือนก่อน +1

    Super 👍

  • @user-su5ne4cm5b
    @user-su5ne4cm5b ปีที่แล้ว +1

    Super...and Thanksssss....

  • @navikaushal1795
    @navikaushal1795 ปีที่แล้ว +1

    Thank you so much Yogesh sir I really want to understand the concept of async await. Thanks again

  • @khanshahbaz3004
    @khanshahbaz3004 ปีที่แล้ว +2

    Thanks bro, I appreciate your way of explaining and the knowledge you share.

    • @YogeshPateliOS
      @YogeshPateliOS  ปีที่แล้ว +1

      Glad you like it. Please like, subscriber and share with you friends :)

  • @user-bf6tw7ll2g
    @user-bf6tw7ll2g 10 หลายเดือนก่อน +1

  • @shubhamkshatriya2609
    @shubhamkshatriya2609 ปีที่แล้ว +1

    Nice explanation. Please start swiftui tutorials.

  • @user-bf6tw7ll2g
    @user-bf6tw7ll2g 10 หลายเดือนก่อน +1

    ❤❤

  • @developertesting130
    @developertesting130 ปีที่แล้ว +1

    that is also good one,Thanks

  • @chetanzala975
    @chetanzala975 ปีที่แล้ว +1

    Thank you such video Yogesh sir :)

  • @bhavesh.gamara5851
    @bhavesh.gamara5851 ปีที่แล้ว +1

    જય દ્વારીકાધીશ યોગેશ ભાઈ

    • @YogeshPateliOS
      @YogeshPateliOS  ปีที่แล้ว

      જય દ્વારીકાધીશ ભાઈ

  • @Mohsinqureshi6491
    @Mohsinqureshi6491 2 หลายเดือนก่อน +1

    Hello Yosgesh, can you please make a video on more than 2 API calls on any screen using
    async/await

  • @user-bf6tw7ll2g
    @user-bf6tw7ll2g 10 หลายเดือนก่อน +1

    Super❤❤

  • @vishalgohil2363
    @vishalgohil2363 ปีที่แล้ว +1

    Good explanation!
    keep it up 🎉

  • @ShakeelAhmed-jb6nu
    @ShakeelAhmed-jb6nu 6 หลายเดือนก่อน

    understanding achi ha but Yogesh hamara do cash ab har Controller me linkhana pary ga so i think achi aproach ni ha ViewController level pay it should be in wrapper please reply.

  • @user-su5ne4cm5b
    @user-su5ne4cm5b ปีที่แล้ว +1

    Sir..Can we have a session on video call , video streaming etc?

  • @ammarulhaq6517
    @ammarulhaq6517 8 หลายเดือนก่อน +1

    Hi Sir,
    In this video, View Controller is tightly coupled to viewModel. So basically view controller is depending on viewModel. How can me make it loosely coupled ?

    • @YogeshPateliOS
      @YogeshPateliOS  8 หลายเดือนก่อน

      Hey, please check my mvvm video on product api there i use protocol so basically you are not depending on viewmodel. We depend on abstract layer protocol. This video is mainly based on Async Await 😄 Thank You

  • @Crazyness.c
    @Crazyness.c ปีที่แล้ว +1

    Try to save api response in core data and realme db or firebase db .

  • @bhavinkansara3393
    @bhavinkansara3393 11 หลายเดือนก่อน +1

    Could you make a video GraphQL ?

  • @crazzykat
    @crazzykat ปีที่แล้ว

    Hello yogesh..do you give online classes to learn iOS development?i want to learn please reply

  • @leonardodavinci2856
    @leonardodavinci2856 ปีที่แล้ว

    Question: When I run the request function in which thread does it run ? Does it run on main thread or uses a qos like .utility. Because when the we get response from data and setting it directly it is giving the error that it needs to be done in the main thread. So just wanted to know which thread it is used by default by the async functions. And also in non async function what is the thread. So like if i didnt had the async function and then I was setting the data in the fetchUsers I think it wont give me any issue as per my experience.
    PS: Nice videos. Wanted to learn concurrency. Very informative.

  • @AmitGupta-xc9gq
    @AmitGupta-xc9gq 11 หลายเดือนก่อน

    How can we send the multiple json object in single post request?

  • @ammarulhaq6517
    @ammarulhaq6517 8 หลายเดือนก่อน +1

    Hi Sir,
    Does @MainActor blocks main thread ?

    • @YogeshPateliOS
      @YogeshPateliOS  8 หลายเดือนก่อน

      Hey, No it is not block the main thread. It call your ui or logic in main thread 👍🏻

  • @umarparacha653
    @umarparacha653 ปีที่แล้ว +1

    multiply images wala bhee
    kr daaa

  • @sagarsharma3414
    @sagarsharma3414 ปีที่แล้ว +1

    How we can pass params,headers and api type(get,post) using this method ?

    • @YogeshPateliOS
      @YogeshPateliOS  ปีที่แล้ว

      In this video we create url and we pass in datatask method. If you want to pass header, type etc first you need to create a urlrequest and then pass it to dataTask(for: urlRequest) ok sagar 🤝
      In request you can add method type, body and header.

  • @pradeepkas10
    @pradeepkas10 ปีที่แล้ว +1

    Hello Yogesh
    Thank you for all content.
    When we can see RXSwift with MVVM videos ?? Please plan this as well if possible, thank you

  • @hunghuynhmanh2397
    @hunghuynhmanh2397 ปีที่แล้ว +1

    import Foundation
    import KRProgressHUD
    import SwiftyJSON
    import Alamofire
    class ApiCall: NSObject, RequestInterceptor {
    static let share: ApiCall = {
    return ApiCall()
    }()
    let retryLimit = 3
    func request(_ apiRouter: URLRequestConvertible, hasProgress: Bool, isShowError: Bool = true, completion: @escaping (JsonResult) -> Void) {
    if !NetworkServices.isNetworkAvailable() {
    if isShowError {
    Toast(text: "Unable to connect to the server, please check your network connection and try again").show()
    }
    completion(.failure(.serverTrustEvaluationFailed(reason: .noCertificatesFound), nil))
    return
    }
    if hasProgress {
    KRProgressHUD.show()
    }
    AF.request(apiRouter, interceptor: self).validate().responseData { response in
    if hasProgress {
    KRProgressHUD.dismiss()
    }
    switch response.result {
    case .success(let data):
    do {
    let json = try JSON(data: data)
    print("- result \(apiRouter.urlRequest?.url?.absoluteString ?? ""): \(json)")
    completion(.success(json))
    } catch {
    completion(.success(JSON.null))
    }
    case .failure(let error):
    print(error.localizedDescription)
    completion(.failure(error, response.response?.statusCode))
    break
    }
    }
    }
    func requestFormData(_ router: URLRequestConvertible, image: ImageModel?, hasProgress: Bool, completion: @escaping (JsonResult) -> Void) {
    if !NetworkServices.isNetworkAvailable() {
    Toast(text: "Unable to connect to the server, please check your network connection and try again").show()
    completion(.failure(.serverTrustEvaluationFailed(reason: .noCertificatesFound), nil))
    return
    }
    if hasProgress {
    KRProgressHUD.show()
    }
    var params: [String: Any]?
    var url: String?
    var headers: HTTPHeaders?
    var method: HTTPMethod?
    if let rt = router as? APIRouter {
    params = rt.parameters
    url = Api.me.baseUrl + rt.path
    headers = rt.headers
    method = rt.method
    }
    guard let pr = params, let u = url, var h = headers, let m = method else {
    return
    }
    h["Content-type"] = "multipart/form-data"
    h["Accept"] = "*/*"
    print("requestFormData")
    print("url: \(u)")
    print("params: \(pr)")
    print("method: \(m)")
    print("headers: \(h)")
    let block = { (multipart: MultipartFormData) in
    URLEncoding.default.queryParameters(pr).forEach { (key, value) in
    if let data = value.data(using: .utf8) {
    multipart.append(data, withName: key)
    }
    }
    if let image = image, let im = ImagePickerManager.loadImage(fileName: image.id), let data = im.resizeImageToData(CGSize(width: 1024, height: 1024)) {
    multipart.append(data, withName: "image", fileName: "\(Date.init().timeIntervalSince1970).png", mimeType: "image/png")
    }
    }
    AF.upload(multipartFormData: block, to: u, method: m, headers: h)
    .responseData { response in
    if hasProgress {
    KRProgressHUD.dismiss()
    }
    switch response.result {
    case .success(let data):
    do {
    let json = try JSON(data: data)
    print("- result: \(json)")
    completion(.success(json))
    } catch {
    completion(.success(JSON.null))
    }
    case .failure(let error):
    print(error.localizedDescription)
    completion(.failure(error, response.response?.statusCode))
    break
    }
    }
    }
    }
    extension URLEncoding {
    public func queryParameters(_ parameters: [String: Any]) -> [(String, String)] {
    var components: [(String, String)] = []
    for key in parameters.keys.sorted(by:

  • @creations_saumya234
    @creations_saumya234 หลายเดือนก่อน +1

    Very detailed explanation...!! Thanks for sharing...

  • @user-bf6tw7ll2g
    @user-bf6tw7ll2g 10 หลายเดือนก่อน +1

    ❤❤