Lazy stored property in Swift Hindi tutorial

Поділитися
Вставка
  • Опубліковано 2 сер 2024
  • Lazy in swift is a stored property which can help you to initialize object only if they are needed. This lazy property swift Hindi tutorial covers how to use lazy var in swift including easy to understand example for the lazy stored property in swift. Lazy property swift is sometimes referred to as iOS lazy variable or lazy var in swift so don't get confused on that as both mean the same thing.
    We will also cover the limitation for swift lazy var which will be helpful for your interview preparations and for your project code. In this video, I am also displaying a comparison between computed property and lazy stored property.
    If you are new to the channel then I would request you to subscribe to the channel as this channel covers swift language tutorial for beginners in Hindi with easy to understand examples.
    I have made some interesting points from an interview perspective, which would help you in your interview preparations.
    Here are the chapters in the video
    0:00 Introduction
    0:16 Today's video summary
    1:10 Stored and Computed property
    2:00 Lazy stored property
    3:40 First code example
    5:44 Second code example
    8:01 Computed vs Lazy property
    10:39 Limitation of lazy property
    10:50 Ending
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ✅ Subscribe to the channel and stay ahead of everyone by following the right way for writing clean code in swift. 🔥🔥🔥🔥🔥
    🔗Click on the link to subscribe: ua-cam.com/users/codecat?sub...
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    🎶 Royalty-free Music: www.bensound.com
    ############################################
    Connect with me on social media
    📧: codecat15@gmail.com
    🐦: / codecat15
    Facebook: / code.cat.792
    Github: github.com/codecat15
    ###########################################
    #lazyInSwift #lazyStoredProperty #lazySwiftHindiExample

КОМЕНТАРІ • 59

  • @faastfood
    @faastfood 2 роки тому

    Best video on lazy till I watch on UA-cam, Finally I understand the concept properly. Thanks Ravi 🙏

  • @dineshgautam1583
    @dineshgautam1583 2 роки тому

    Thank you for this great knowledge

  • @nareshnayak4039
    @nareshnayak4039 3 роки тому +1

    One of the best channel for iOS development. Your teaching is unique you explain the things comparing to real world that is awesome, but if you can explain in English lot many members will watch your videos

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      Am glad this video was helpful Naresh, and welcome to the channel. I keep my videos in Hindi as lot of my audience wants me to keep it in Hindi but I do try my best to add captions in the video whenever I can buddy and once again thank you for your kind words

  • @natureloverspakistan
    @natureloverspakistan 3 роки тому +2

    i was also confused but you did very good job be showing the difference with practical example

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      No problem am glad i was able to help and clear your doubts 😊

  • @DigitalHole
    @DigitalHole 3 роки тому +1

    Well explain ravi.. Keep on uploading great content 🔥

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      Thank you, plz do ask questions on this topic and do share it with your iOS group

  • @natureloverspakistan
    @natureloverspakistan 3 роки тому +2

    wow very helpful..perfect example . thanks master Sahb

  • @shahbaze63
    @shahbaze63 3 роки тому +1

    explaination at peak.. Thanks..

  • @nagarajangeetha6586
    @nagarajangeetha6586 2 роки тому +1

    Good Explanation , Happy to watch your videos

    • @CodeCat15
      @CodeCat15  2 роки тому

      Thank you so much 🙂, please feel free to ask questions and do share the channel with your iOS group

  • @sudhakard5273
    @sudhakard5273 5 місяців тому

    good video. What are the real time examples for lazy keyword usage?

  • @shubhangisingh4376
    @shubhangisingh4376 3 роки тому +2

    Hey Ravi, I am new to this channel but I have watched your most of videos in few days only and it was very helpful for me. I am very confused with the Provising Profiles like which certificate is used for which purpose. Can you make a video on that?

    • @CodeCat15
      @CodeCat15  3 роки тому +2

      Hello Shubhangi, welcome to the channel and I am glad you found most of these videos helpful and worth your time. I will surely try to make a video on the provisioning profiles and their usage. Please do share this channel with your iOS developer friends or even beginners who are learning iOS development and swift programming on what's app or Facebook

  • @payalmalekar6529
    @payalmalekar6529 3 роки тому +1

    Well explained 👍

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      Hello Payal, welcome to the channel. I am glad this video was helpful to you. Plz do feel free to ask questions on this topic and do share the video with your iOS group on WhatsApp or Facebook 😊

  • @jaisinghsisodia8202
    @jaisinghsisodia8202 3 роки тому +2

    Very well explained Ravi, now I got to know the actual difference between lazy and computed property. Could you please make a video on multithreading and how to make thread-safe properties .

    • @CodeCat15
      @CodeCat15  3 роки тому

      more will be explained in a video than this comment but usually if you want something to just wait till you kick off another task I usually use serial queues, however I want to know if you are referring to a use case where two threads are trying to access a single resource? or something else because literally there are so many use case which I can think of here just want to get a use case similar to what you have in mind and maybe add two or three more examples to it.

    • @jaisinghsisodia8202
      @jaisinghsisodia8202 3 роки тому +1

      Code Cat Yes Ravi, I would like to know that same time multiple thread accessing same resource.For example we are downloading multiple images and we want to pause , cancel without freezing UI. such kind of events by using operations and operation queues. If you can make video it . It would be more helpful for me . Because the way you explain. It’s hits me quickly with your examples 😊😊

  • @Shade_with_me_7
    @Shade_with_me_7 2 роки тому

    Hello Ravi , thanks for amazing video.
    I tried to use Lazy ,
    but when I try to use with "let" , compiler give me error "lazy can not be used on let"
    because in lazy variable as we saw , we can set value only once (unable to get updated value 100 when we set it ComplexTask.firstElement == 100) , so why "let" is not allowed ?
    also why static property and function , in this ComplexTask class ? is it related to lazy var or just demo purpose.
    and what will be best practice to use static variable or instance variable.

  • @emdutt4012
    @emdutt4012 2 роки тому

    Brother do u have any video on access control in swift.?

  • @deepikasahu8237
    @deepikasahu8237 3 роки тому +1

    👍👍

    • @CodeCat15
      @CodeCat15  3 роки тому

      Welcome to the channel Deepika, please do ask questions on this topic and do share the channel with your iOS group on WhatsApp or Facebook

  • @dipikasahu3298
    @dipikasahu3298 3 роки тому +1

    Waiting for your next video 🙂

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      Am on vacation as of now so didn’t post any video this Sunday, will post this week 😊

    • @dipikasahu3298
      @dipikasahu3298 3 роки тому +1

      Enjoy🤘

    • @CodeCat15
      @CodeCat15  3 роки тому

      Thank you Priyanka

  • @sunilchauhan-BhagatSingh
    @sunilchauhan-BhagatSingh 2 роки тому +2

    I want to start a job as ios developer plz give me some guidence . I learn swift documentation only its enough for beginner level

    • @CodeCat15
      @CodeCat15  2 роки тому

      This is a broader discussion but I did write a blog on this on medium, here’s the link for the same I hope it helps
      medium.com/swlh/how-to-start-your-journey-as-an-ios-developer-a23b835b1fed
      If the site does not open, please try the above in incognito mode

  • @pratikgupta7373
    @pratikgupta7373 3 роки тому +1

    Thanks,
    what is object mapping in swift
    will u create a detailed video on this topic

    • @CodeCat15
      @CodeCat15  3 роки тому

      Object mapping is where you assign value from object a to a similar property in object b. There are various ways to achieve this but the one way i can tell you is the decodable protocol where swift does mapping of our json object to our swift models. I have few examples in the api series where am explaining this in detail
      Link: ua-cam.com/video/RiuvxmoU37E/v-deo.html

    • @pratikgupta7373
      @pratikgupta7373 3 роки тому +1

      @@CodeCat15 thanks

  • @dipikasahu3298
    @dipikasahu3298 3 роки тому +1

    In case of copy , will the retain count increase by 1 for the original one?

    • @CodeCat15
      @CodeCat15  3 роки тому

      what do you think Priyanka? let's hear that out first and it's okay if the answer is wrong just let me know what do you think happens when you write copy and sorry for the delayed response

  • @ahmedpakistan3376
    @ahmedpakistan3376 3 роки тому +1

    lazy memory sy kab remove hota ha?
    suppose lazy assing and object of class is remove lazy will remove from memory ?
    second thiing suppose strong variable we created
    so object is not created will the veriable exist in memory or not

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      Its same like other objects agar koi strong reference aapne create nahi kiya hai to use case mai swift ARC aapke lazy object ko memory se clear kar dega. Class deallocate jab hoga tab aapka lazy object bhi memory se clear ho jayega.
      Maine ARC aur strong reference behavior ARC k video mai explain kiya hai aap usse check kare ARC k is behavior ko detail mai jaan k liye
      Link: ua-cam.com/video/XAlXnApplk0/v-deo.html

  • @dipikasahu3298
    @dipikasahu3298 3 роки тому +1

    Hello Ravi,
    I have a tableview with 100 plus number of rows(dynamic data from api). Now when I get response from the api, shall I store all the 100 data in array because it will take unnecessary memory. Is there any optimised way?

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      Hello Priyanka, If your API supports pagination (top and skip) then rather than bringing 100 records from the API just request for top 30 records and then when the user scrolls down to the table view last row request the next 30 that way you can load the data a little quick. if your API does not have pagination then how you are doing it should be fine and is the preferred approach.

    • @dipikasahu3298
      @dipikasahu3298 3 роки тому +1

      Thanks for responding. My api is not supporting pagination.

    • @CodeCat15
      @CodeCat15  3 роки тому

      @@dipikasahu3298 okay cool then, how you are doing it should be fine, are you facing issues with your current implementation?

    • @dipikasahu3298
      @dipikasahu3298 3 роки тому +1

      No, just wanted to confirm the correct way.

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      Cool, so was i able to answer your question? If not please do ask

  • @Umairkhan-ql5id
    @Umairkhan-ql5id 2 роки тому +1

    Why is it not safe for multi threading.

    • @CodeCat15
      @CodeCat15  2 роки тому

      From the Swift programming documentation: If a property marked with the lazy modifier is accessed by multiple threads simultaneously and the property hasn’t yet been initialized, there’s no guarantee that the property will be initialized only once.
      Source: docs.swift.org/swift-book/LanguageGuide/Properties.html

  • @tanmayagarwal1356
    @tanmayagarwal1356 2 роки тому

    What is the meaning of "Lazy is not thread safe"?

  • @natureloverspakistan
    @natureloverspakistan 3 роки тому +1

    Please make a tutorial on combine framework using storyboard view controllers pasing data one to one and one many .

    • @natureloverspakistan
      @natureloverspakistan 3 роки тому

      Ravi bro ..???

    • @CodeCat15
      @CodeCat15  3 роки тому +1

      Before i explain that i need to explain a concept of binding and observer property wrappers because only then we will know when to use what otherwise its going to be a little challenging as to why am i using binding or observers

    • @natureloverspakistan
      @natureloverspakistan 3 роки тому +1

      @@CodeCat15 ok sir I will wait

    • @natureloverspakistan
      @natureloverspakistan 3 роки тому

      @@CodeCat15 wese jahan tk mujh yad he ap property observer p pehly b tutorial bna chuke , will set and didset .

    • @natureloverspakistan
      @natureloverspakistan 3 роки тому +1

      oh i just checked property observer and observer property both are different..

  • @rajanmaheshwari
    @rajanmaheshwari 3 роки тому +1

    You should have given example why lazy is not thread-safe

    • @CodeCat15
      @CodeCat15  3 роки тому +2

      As per apple developer documentation notes the argument is if a lazy property is not yet initialized and multiple thread access the lazy property then there’s no guarantee that it will be initialized only once. You could end up with multiple instances of that object in the memory and hence its not thread safe.
      Sorry about not explaining this in the video and good catch Rajan thank you
      Link to dev doc: docs.swift.org/swift-book/LanguageGuide/Properties.html