Learning About Initialization Properties in iOS Swift 5


Hello guys, lately I have watched a good video to learn about iOS programming. It's CS 193P from standford university on youtube. Although I have learned iOS programming more than 4 years. I'm amazed about things that are learned.

Many things I haven't noticed about deep language in swift. I'm so glad that swift is so powerful language. Thanks to the ones who created it. I haven't finished all tutorial videos. But soon day after day I will watch it. Never stop learning when we're in technology haha.

Today I'm gonna share something simple that I haven't used in my project. But I think on the future, I will try to use it. So I will call it "Initialization Properties". You can create "set get property" with closure in swift. It's so easy to do it like example below. And you can do willSet and didSet property condition in method. It's very useful for me when I'm usually put initialization in viewDidLoad.

I haven't found this powerful syntax in java, but I haven't expierenced in kotlin. And I think it must be followed by other programming languages. Easy to use and easy to understand that's what I think about swift.


Try run this in playground project and see results on the right console :


If you don't use "set get" inside closure and just using return. It will behave like get method and it will be get property only. It means you cannot set the property to other value. And about "willSet and DidSet" will run when you initialize the property. You can check if print method will work if the count property is initialized.

So that's it, our topic about initialization. If you have any question related to this article. I'm glad I can help ye all. Thanks for visiting my simple blog. Have a nice day.

Popular posts from this blog

How to restart the app with flutter Android and iOS

How to have ConstraintLayout inside ScrollView and ScrollView inside ConstraintLayout Android

Missing system image Android Studio solution