Start Using Lazy | Swift 5, Xcode 10

  Рет қаралды 12,966

Kilo Loco

Kilo Loco

Күн бұрын

Today we go over why you should start using the lazy keyword in your apps. There are a lot of ways to optimize your app's performance and using the lazy keyword is one of the easiest ways to do it.
By the end of this tutorial, you will know why using lazy is important and how it can make your app be much faster.
** Show Notes and Links **
Need Help?
kiloloco.com/membership
Project Files:
kilo-loco.teachable.com/cours...
Kyle Lee on Social Media:
www.kiloloco.com
KZfaq- / kiloloco
Twitter- / kilo_loco
Instagram- / kilo_loco
--------GEAR ------
Code Passionately T-Shirt
a.co/d/53OkIu0
Laptop - 2017 MacBook Pro
amzn.to/2tk5yLr
Microphone - PowerDeWise Lavalier Microphone
amzn.to/2In9PCh
DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, we’ll receive a small commission. This helps support the channel and allows us to continue to make videos like this. Thank you for the support!

Пікірлер: 80
@vamsi3877
@vamsi3877 5 жыл бұрын
This is most productive youtube channel i have ever found.Thankyou kyle.
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Glad you like it. This past week has been an experiment though. I do plan on continuing to put out content, but my experiment has given me insight as to what type of content I should focus on and how often I should produce it.
@alifarhadi5704
@alifarhadi5704 4 жыл бұрын
The best explanation for lazy property that I have seen on KZfaq. Thanks
@phanikella8769
@phanikella8769 4 жыл бұрын
the best explanation for lazy property... thanks kyle 🙂
@MrBhupeshpruthi
@MrBhupeshpruthi 3 жыл бұрын
Thanks for simplifying things..Your videos are always helpful..
@MrDonhekel
@MrDonhekel 5 жыл бұрын
also Lazy computed properties are only calculated once when they’re first accessed.
@jacktoddy9783
@jacktoddy9783 5 жыл бұрын
Great video - really useful to build into my App = Many thanks.
@vincentjoyhere
@vincentjoyhere 4 жыл бұрын
Thanks for the video. Really informative.
@rasheedm2084
@rasheedm2084 5 жыл бұрын
This video clarified the benefit of Lazy in great way .. thanks Kilo
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Glad I could help you out 😊
@JasonMitchellAZ
@JasonMitchellAZ 4 жыл бұрын
Great demo showing how ‘lazy’ works
@DesperadoAH
@DesperadoAH 5 жыл бұрын
Nicccce I was using it but didn't know about everything, thank you KL
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
My pleasure 😇 If there’s anyway to make my content better or if there’s a topic you want covered, please let me know.
@alirezaaj1957
@alirezaaj1957 5 жыл бұрын
such a good topic, and specially explanation and example . that was an eye opening video about lazy and it's usage . one reason that i really like most of your videos is because , when you try to talk about a topic, you share all useful experiments that you have gained and extract of them and pitfalls and tips . thanks a lot Kilo
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Really glad you feel that way about the content. If you truly like the channel, please share it with as many people as possible 😇
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Really glad you feel that way about the content. If you truly like the channel, please share it with as many people as possible 😇
@belafekete3125
@belafekete3125 5 жыл бұрын
Thanks Kyle!
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Always a pleasure 😊
@GoingWalkabout
@GoingWalkabout 5 жыл бұрын
Thx, great example you are giving here.
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
No problem! I always try to make things as clear as possible
@davidandreasson1434
@davidandreasson1434 5 жыл бұрын
THANKS, just thanks! I knew this, but It wasn't obvious for me! Now it is!!
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
It's my pleasure to add another tool to your tool belt 😉
@saibalaji4713
@saibalaji4713 4 жыл бұрын
Thank you sir 😊
@Kilo_Loco
@Kilo_Loco 4 жыл бұрын
always a pleasure
@AdelUI
@AdelUI 5 жыл бұрын
Kilo loco , crate a realm application using api and realm , EX : news app So next month , i'll support you in u're website . You're the best
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
This video might be helpful if you’re looking into realm kzfaq.info/get/bejne/nqlml699x8y5iJc.html I will also be covering how to save data from an api soon trello.com/c/wq9xUKui
@GG-hk5iz
@GG-hk5iz 4 жыл бұрын
Hey Kyle Can you please explain what is purpose or how adding lazy in closure eg u did in imageView is beneficial in same way as u explained very well for expensiveNumber
@HarshitKumar-br3iz
@HarshitKumar-br3iz 5 жыл бұрын
Awesome
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Thanks!
@_Forever555
@_Forever555 4 жыл бұрын
Can it be used to get the last result of db call in a asynchronous function?
@siddharthtiwari4849
@siddharthtiwari4849 5 жыл бұрын
Thanks sir
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
My pleasure. If there’s anyway to make my content better or if there’s a topic you want covered, please let me know.
@Cdswjp
@Cdswjp 4 жыл бұрын
At 8:00, in the ibaction, what if we put that code in the background thread so we could interact with the ui still.... and say we had initialized the service in viewDidAppear instead of viewDidLoad to gain the fast startup but get a head start on the process too... My question is - what could we do to stop that looping service if we decided to navigate to a different screen before the looping service completed? Thanks fam
@lucienchu9649
@lucienchu9649 5 жыл бұрын
Nice explanation. I am new to Swift, so there are many new stuff here. Self, lzay, weak, some closure stuff, when should I used them what they are potential problems. Still struggling with them. THX
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
You might find these videos helpful kzfaq.info/get/bejne/j9eYqbmqzqvUeWQ.html kzfaq.info/get/bejne/rLmEZ7h_mdmVm5s.html
@TheAhmadReza
@TheAhmadReza 5 жыл бұрын
Awesome! Could you pease include a link of you'r Xcode color theme file ?
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
As of right now I don't have a link to it but I plan on having a page setup on kiloloco.com that will allow people to download the theme in the near future.
@adamkenton2585
@adamkenton2585 5 жыл бұрын
Hey man nice video, and I really like your color scheme, how is it called ?
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
It’s a custom theme that I put together. I’m going to share it on kiloloco.com in the near future
@donathmm3881
@donathmm3881 5 жыл бұрын
Good Video
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Thanks. Glad you liked it
@VeryBlueBot
@VeryBlueBot 4 жыл бұрын
Very clear and useful thanks! Quick question: So from my understing, you wonldn't use `lazy` on variables you need in `viewDidLoad` right? As they mite be not ready when `viewDidLoad` triggers? Am I understanding this right? Thanks again! happy to find your channel
@Kilo_Loco
@Kilo_Loco 4 жыл бұрын
you can use them in viewDidLoad too. they will simply be created during that lifecycle event
@VeryBlueBot
@VeryBlueBot 4 жыл бұрын
​@@Kilo_Loco So if Im using a variable that is not populated/initiated yet (time heavy async result) in viewDidLoad won't I get an error? Assuming Im not checking if its not nil? in any case I wont be able to use the response content as it is not existing yet. Lets say its a really big http request that takes a couple of seconds to complete and viewDidLoad is firing ... Or... viewDidLoad is firing only after everything is loaded? Including lazy variables?
@vivekgarg8944
@vivekgarg8944 5 жыл бұрын
Hi Kilo thnks for the video. Can you plz explain other usages of "lazy" keyword.
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Using lazy for expensive functionality and for grouping code together are my primary uses for it. Not really sure what else lazy would be used for outside of that.
@vivekgarg8944
@vivekgarg8944 5 жыл бұрын
​@@Kilo_Loco Thanks for the reply Kilo. I read somewhere that we can use Lazy keyword in Higher-order functions. I wish I could explain to you but they are not clear to me as well. I'll definitely share with you whenever I'll find them.
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Well higher order functions usually loop through all the items in collection. I suppose you could access your lazy variable inside the higher function in the event that you want to do something expensive on certain items in the collection. It really comes down to the same concept though. I wouldn’t really be able to give a relevant example myself since this would be a very particular use case that most developers would face. I know I haven’t come across something like this before
@piotriosdev4158
@piotriosdev4158 5 жыл бұрын
Hi Kilo! You’ve got nice xcode’s colors. Could you give me please an information what colors do you use in xcode?
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
You can get the theme from here kiloloco.com/store
@piotriosdev4158
@piotriosdev4158 5 жыл бұрын
thx!
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
It’s my pleausre
@gjermundification
@gjermundification 5 жыл бұрын
9:13 Do any of you know where in the Swift documentation does it explain why a closure requires trailing ()? I assume it's called execute anonymous function.
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
I didn’t mention it until 13:13 . Idk where it says that in the documentation, probably under lazy, but essentially since it’s a closure that actually needs to be executed right then and there, that’s why we have to have the () at the end.
@gjermundification
@gjermundification 5 жыл бұрын
Kilo Loco You are a naturist! Or should I say natural? I assume so too, hence I’d like to read the official documentation. It’s done more or less the same in ECMA Script.
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
By all means check the documentation. You don’t really have to though because if you try to write out a lazy property by setting it to a closure without the () I think it throws a compile error anyways
@zehualin6686
@zehualin6686 5 жыл бұрын
Is there build time optimisation in Swift 5 for the lazy keyword? Because normally using the lazy keyword would increase your build time as it gets type checked, and you really only want to use the lazy keyword if the initialisation is too expensive.
@freerider6300
@freerider6300 5 жыл бұрын
You can specify the type as Kilo did with the UIView, I assume
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
So as I was demonstrating, the constant property would be initialized with the view controller so yea its too expensive. From my experience lazy doesn't increase build time and decreases in most cases.
@jhgjhgjhfjyhgjhgj5385
@jhgjhgjhfjyhgjhgj5385 5 жыл бұрын
ye next video about multithread
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Thanks for the suggestion. I will add that to the list of topics to cover trello.com/c/UTZF7hMb
@adinolivier
@adinolivier 5 жыл бұрын
You should have more views seriously
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Thanks! I’m really working hard on delivering content that is valuable to people. Any videos that you find valuable, please share them so they can help more people.
@maximkrouk1697
@maximkrouk1697 5 жыл бұрын
Would be cool if you make a video about advanced custom vc transitions, like in AppStore for ex (without snapshots, just real views), guess i’ve never seen such a video) (Here is one at raywenderlich.com, but they use a snapshot)
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Yea I plan I’m doing some animation videos soon
@vishnusatheesh6645
@vishnusatheesh6645 5 жыл бұрын
Adaptive designing
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Thanks! If there’s anyway to make my content better or if there’s a topic you want covered, please let me know.
@vishnusatheesh6645
@vishnusatheesh6645 5 жыл бұрын
Kilo Loco static method , file private etc
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Hope you find this helpful State & Class kzfaq.info/get/bejne/ebxglt192surlX0.html Access Control kzfaq.info/get/bejne/iZ2Tppmfurjad2Q.html
@tenminutetokyo2643
@tenminutetokyo2643 4 жыл бұрын
DOOD!
@superbrianable
@superbrianable 5 жыл бұрын
@twitter
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
@kilo_loco
@wazawoo
@wazawoo 5 жыл бұрын
Yooooo
@freerider6300
@freerider6300 5 жыл бұрын
I got hooooooes calling
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
BRUUHHH
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
Not me, I'm just a family man 😛
@raimitis
@raimitis 5 жыл бұрын
Lazy var usage is clear for expensive calculations, but still not clear for me why to use for views (how you made example). What is the difference between lazy var and var someImageView: UIImageView = {}()? Why I would use lazy for view component instead of simple var. Only case where I saw lazy benefit for view management was in case I would like to get view width or height. More info here: kzfaq.info/get/bejne/ZuCliqmT1MvYmGQ.html
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
lazy wouldn't give you any real gains in performance for views. As I demonstrated, its mainly a developer preference that allows you to configure your views all in one place as opposed to having that code spread out across your view controller. Since your views are likely to be put on the screen before the view will appear, you'll actually see no gain at all.
@raimitis
@raimitis 5 жыл бұрын
@@Kilo_Loco That is what I wanted to hear! Thank you!
@Kilo_Loco
@Kilo_Loco 5 жыл бұрын
No problem 😁
Use Closures Not Delegates | Swift 5, Xcode 10
14:52
Kilo Loco
Рет қаралды 24 М.
Laid Off, AI is Coming
13:06
Kilo Loco
Рет қаралды 3,5 М.
Задержи дыхание дольше всех!
00:42
Аришнев
Рет қаралды 3,8 МЛН
No empty
00:35
Mamasoboliha
Рет қаралды 10 МЛН
Alex hid in the closet #shorts
00:14
Mihdens
Рет қаралды 18 МЛН
لقد سرقت حلوى القطن بشكل خفي لأصنع مصاصة🤫😎
00:33
Cool Tool SHORTS Arabic
Рет қаралды 28 МЛН
Dependency Injection | Swift 4, Xcode 9
16:40
Kilo Loco
Рет қаралды 16 М.
Error Handling | Swift 5, Xcode 10
38:10
Kilo Loco
Рет қаралды 8 М.
iOS Concurrency and Threading - iOS Interview Question - Swift
7:50
Advanced Swift: Making Programmatic Auto Layout Easy through Extensions
25:38
DispatchGroup: Waiting for Data | Swift 4, Xcode 9
18:39
Kilo Loco
Рет қаралды 31 М.
Loops and Hash Maps Job Preparation Interview Question
15:55
Lets Build That App
Рет қаралды 20 М.
When to Semaphore vs Dispatch Group! Careful Multithreaded Shared Resource
11:11
Parsing JSON Just Became Super Easy in Swift 4 with Decodable
19:30
Lets Build That App
Рет қаралды 274 М.
UIAlertController Refactor - Xcode 10 - Swift 4.2
11:56
Sean Allen
Рет қаралды 23 М.
The Story of Next.js
12:13
uidotdev
Рет қаралды 560 М.
Задержи дыхание дольше всех!
00:42
Аришнев
Рет қаралды 3,8 МЛН