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.
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!
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
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
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?
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 = "")
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.
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
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?
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.
A tip: watch series at Flixzone. Been using them for watching loads of movies during the lockdown.
@Aaron Maximus Yup, have been using flixzone for since november myself :)
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!
Thank you so much, I searched so much info and I only got it until I saw your video :D
Hello, Brian! It would be nice if you could make a video about nsoperationqueue or about multithreading in general
That will be great. I am also waiting for that video where we handle multiple requests and resolve concurrency issues.
Very useful... Excellent video... Thanks for sharing
Great video! i had no idea a retain cycle could occur by using self, thanks!!
watching this in 2018. it's still helpful
thanks a lot, was looking for an explanation for this for a long time.
Great video! If you could do a video about all the shortcuts you have been using, that would be awesome!
原来你也看ryuuutv好巧
Lets Build That App 哈哈是啊!也是这几天在看的
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.
I'm working wit java it's not that bad why do you think it's bad
Thanks. Keep up the good work.
Thanks a lot.
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
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
thanks , which episode is talking about accessing data from firebase closure? (not accessing data from firebase)
May I ask which computer/keyboard you are using here? The clicky sounds are just too amazing to ignore for me lol.
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?
same question...!!
If class holds reference of the closure then we have to use capture list. Other wise its not needed.
Helpful, good work man. Thanks :)
Hi Brain It seems to be very interesting to learn the Retain Cycles on Closures.
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?
Sometimes yes, sometimes no.
Yes..when working on main thread
Very informative!
what's the point of asHTML being a variable rather than a function? Why would you want this?
Its a bit of a contrived example.
Why is that we need to specify the closure as lazy?
Can you please explain a bit more?
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 = "")
@@jakubkracina1583 Thanks!
Got it!
Briant is the man!
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.
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
can you make a video how to make generic class url request plzzzsir
Pretty Good Stuff!
Good one thank you
Swift Code can look really really crazy and unreadable :-/
THANK YOU
Cool Thanks
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?
The example given here is a bit contrived but I've found myself declaring properties like this once or twice in my classes.
I understand little