Swift Fun Algorithms: Closure Reference Cycles

Поділитися
Вставка
  • Опубліковано 29 гру 2024

КОМЕНТАРІ •

  • @BergerBytes
    @BergerBytes 7 років тому +14

    If you don't expect 'self' to ever be nil when calling the closure you can use [unowned self] in the capture list rather than weak. This removes the need to unwrap the 'self' property.

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

      A tip: watch series at Flixzone. Been using them for watching loads of movies during the lockdown.

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

      @Aaron Maximus Yup, have been using flixzone for since november myself :)

  • @rogerwprice
    @rogerwprice 7 років тому +5

    Yes - that is the reason why Swift requires you to use 'self' to reference class variables in closures - it is to remind/warn you that you may have a retain cycle!

  • @oscara9709
    @oscara9709 4 роки тому

    Thank you so much, I searched so much info and I only got it until I saw your video :D

  • @MaximGolovlev
    @MaximGolovlev 7 років тому +11

    Hello, Brian! It would be nice if you could make a video about nsoperationqueue or about multithreading in general

    • @greenblade29
      @greenblade29 7 років тому +1

      That will be great. I am also waiting for that video where we handle multiple requests and resolve concurrency issues.

  • @karunakarbandikatla9462
    @karunakarbandikatla9462 7 років тому

    Very useful... Excellent video... Thanks for sharing

  • @Noahnrg22
    @Noahnrg22 7 років тому

    Great video! i had no idea a retain cycle could occur by using self, thanks!!

  • @changjeffrey829
    @changjeffrey829 6 років тому

    watching this in 2018. it's still helpful

  • @RohanLokeshSharma
    @RohanLokeshSharma 7 років тому

    thanks a lot, was looking for an explanation for this for a long time.

  • @jeremychai6991
    @jeremychai6991 7 років тому +1

    Great video! If you could do a video about all the shortcuts you have been using, that would be awesome!

    • @LetsBuildThatApp
      @LetsBuildThatApp  7 років тому +2

      原来你也看ryuuutv好巧

    • @jeremychai6991
      @jeremychai6991 7 років тому +1

      Lets Build That App 哈哈是啊!也是这几天在看的

  • @a.rubio.a
    @a.rubio.a 7 років тому +9

    The way you were using «this» instead of «self» brought me nightmares from the times I used to code in Java. Flagging this as offensive.

    • @theAppleWizz
      @theAppleWizz 7 років тому +1

      I'm working wit java it's not that bad why do you think it's bad

  • @LuxeNomad55
    @LuxeNomad55 7 років тому

    Thanks. Keep up the good work.

  • @yrmentor
    @yrmentor 7 років тому

    may I ask how can we access the data from firebase closure, I know there are lots of similar post in stackoverflow, however, no one have a good answer.
    Recently I created a project that observe snapshot and append the value to the object, it works fine, it also can print out the value within closure, for example print(dog.name) is ok in closure, but outside the closure, it become empty, how can we fix this? thank you very much

    • @LetsBuildThatApp
      @LetsBuildThatApp  7 років тому

      Firebase is pretty straightforward for accessing and persisting data. If you want additional lessons, you can checkout the Instagram Firebase course here: www.letsbuildthatapp.com/course/instagram-firebase

    • @yrmentor
      @yrmentor 7 років тому

      thanks , which episode is talking about accessing data from firebase closure? (not accessing data from firebase)

  • @sabirayaz7893
    @sabirayaz7893 6 років тому

    May I ask which computer/keyboard you are using here? The clicky sounds are just too amazing to ignore for me lol.

  • @discover-japan
    @discover-japan 7 років тому

    Hello Brian, I have a doubt. Do we have to capture self every time when we try to access something (some property of a class) from inside a closure? Is this the right practice?

    • @sadanand12341
      @sadanand12341 7 років тому

      same question...!!

    • @MrViney333
      @MrViney333 7 років тому

      If class holds reference of the closure then we have to use capture list. Other wise its not needed.

  • @vaibhavsingh6886
    @vaibhavsingh6886 7 років тому

    Helpful, good work man. Thanks :)

  • @dhamodaransrinivasan1224
    @dhamodaransrinivasan1224 7 років тому

    Hi Brain It seems to be very interesting to learn the Retain Cycles on Closures.

  • @foocux
    @foocux 7 років тому

    So, this means that everytime we use closure and we are to use a self reference we have to use weak self to avoid retain cycle?

  • @naeem87
    @naeem87 7 років тому

    Very informative!

  • @gothops154
    @gothops154 7 років тому

    what's the point of asHTML being a variable rather than a function? Why would you want this?

  • @revanthkausikan2564
    @revanthkausikan2564 5 років тому

    Why is that we need to specify the closure as lazy?
    Can you please explain a bit more?

    • @jakubkracina1583
      @jakubkracina1583 5 років тому +1

      asHtml is property and all properties must be defined or they must be optional (so they are created with nil value). And because asHtml closure have access to properties name and text, which are defined after init, you must tell that asHtml is lazy. So it is initialized after you call it. It's possible do it without lazy, you should define value of closure in init for example, or name and text should have value for example empty string (var name = "", var text = "")

    • @RevanthKausikan
      @RevanthKausikan 5 років тому

      @@jakubkracina1583 Thanks!
      Got it!

  • @cinquain0
    @cinquain0 6 років тому

    Briant is the man!

  • @viktorkuzmanov3086
    @viktorkuzmanov3086 7 років тому

    Why are you using "?" instead of "!" to force unwrap the properties? Great video give us more like this videos that are related to apple swift documentation because for us beginners these types of videos are very informative and helpful.

  • @suleymanomari5226
    @suleymanomari5226 7 років тому

    Hello Brian,
    Can you please create more apps with firebase as an example. Can you create the snapchat app and also a game would be nice. Please Brian.
    Thanks

  • @jaiganesh6601
    @jaiganesh6601 7 років тому

    can you make a video how to make generic class url request plzzzsir

  • @sheingng1495
    @sheingng1495 7 років тому +1

    Pretty Good Stuff!

  • @prasadbetha2741
    @prasadbetha2741 5 років тому

    Good one thank you

  • @randomcontrol
    @randomcontrol 5 років тому +1

    Swift Code can look really really crazy and unreadable :-/

  • @hectormejia499
    @hectormejia499 6 років тому

    THANK YOU

  • @SevenDeMagnus
    @SevenDeMagnus 6 років тому

    Cool Thanks

  • @w0mblemania
    @w0mblemania 7 років тому

    Just an aside: does anyone know why you would use a construct like "lazy var asHTML: () -> String" in the first place? It's probably a contrived example, but it seems like it's going out of its way to make things difficult. Why wouldn't one just use a simple function that returns a String?

    • @LetsBuildThatApp
      @LetsBuildThatApp  7 років тому

      The example given here is a bit contrived but I've found myself declaring properties like this once or twice in my classes.

  • @muhsincan.yilmaz
    @muhsincan.yilmaz 2 роки тому

    I understand little