Such Beautiful Code, I literally aspire to write code like you some day! Thank you for the posting the videos about enums. Enums are my bestfriend now are so powerful.
Wow, thank you! It might have something to do with the fact that by the looks of your profile photo, you are closer to my age than you might be to some of the other content providers. Thank you for that lovely comment.
@@StewartLynch Yes, that's I can't understand) We could return just wrappedValue.trimingCharacters(), could't we? without defining any property. What did I miss?)
@@shurale85 If you try that, you will end up with infinite recursion since you will be constantly modifying the wrapped value. Take a look at the error you get when you try to do that,
Why are the initializers required in some cases but not others? And then, can you explain at a deeper level what the property wrapper is actually doing when invoked? Is this basically equivalent to immediately calling a function on a new object? The thing I am finding hardest about Swift is that there is so much black-boxed "magic" scattered throughout the language. All these features exist that involve decorator keywords, so I end up writing code the 'hard' way because I simply don't know these features exist. Also, the part where you have to set a default value arbitrarily on the line where the property wrapper is invoked seems like it would be very unintuitive to someone else reading the code. I don't like how that looks - and it leads back to my trying to understand why the initializers requirements are the way they are in some of these examples.
The initializer is required any time you have an additional properties or if you are going to be transforming the wrappedValue. Since these are structs, we want to ensure that all properties are initialized. In my examples, the only time I do not have an initializer is when I am accessing the projected value (Example 1). In this case we do not need to initialize the wrapped value since it is never accessed, We only access the actual property and its projected value. As for setting a default value, I agree that it is not intuitive, but it will be overridden anyway when an instance of the struct is initialized. PropertyWrappers are indeed a bit confusing. By the sounds of it, I have not done a particularly good job explaining them. I will see if I can put something else together in the future that will clarify more.
structs don't require an initializer unlike classes, however you can utilize an initializer for a struct if you need. In all of examples initializers are a must because you want your functionality to be implemented as soon properties get any value. Thus, if the author of the channel haven't used initializers for structs, he wouldn't have got the expected result on the property from the first initialization. Sound misleading , I know, but you have to practise to understand better. I , for one , always rewatch videos to get it. And that's no hard way, that's a necessity.
BTW, the explanation in the video is nearly flawless, if you find it too difficult , you should take easier classes. Perhaps that was not at your level .
I don't get tired rewatching such wonderful videos.
Such Beautiful Code, I literally aspire to write code like you some day! Thank you for the posting the videos about enums. Enums are my bestfriend now are so powerful.
You are the BEST. It's unbelievable how good you are in teaching. I'm a super fan. Thank you so much.
Wow, thank you! It might have something to do with the fact that by the looks of your profile photo, you are closer to my age than you might be to some of the other content providers. Thank you for that lovely comment.
Thank you, this helped me a lot. I was totally lost with projected values and your code was quite didactic.
Glad it helped!
Great explanation with nice examples
OMG this guy is a treasure! Thank you a lot for your work!
Thanks. Glad you are enjoying the videos
Your tutorials are the best.
Another good session
nice explanation
at 07:00 you used additional property text. What is the adv of it? Can we use just wrappedValue? thank you!
As you see at 7:52 we do a transformation on that wrapped value where we trim white space and return the text instead
@@StewartLynch Yes, that's I can't understand) We could return just wrappedValue.trimingCharacters(), could't we? without defining any property. What did I miss?)
@@shurale85 If you try that, you will end up with infinite recursion since you will be constantly modifying the wrapped value. Take a look at the error you get when you try to do that,
@@StewartLynch ah. Thank u very much for your patient and useful content!
For example, I would like to use ready @AllCaps and @Trimmed property wrappers for one var Name. How can I do that?
Last example is cool.. also generic. Thank you so much. Do you have some videos where we use custom property wrappers in real project?
Not at the moment, no.
I've got a silly question. How to use two propertyWrappers on one property.? By way of example, @State @Blablabla var num
Give me an example of what you are trying to do that would required two property wrappers
@@StewartLynch okay, I will write a clear piece of code tomorrow to avoid ambiguity. Thank you in advance.
@@StewartLynch never mind. I figured it out on my own. Thank you any way.
Why are the initializers required in some cases but not others? And then, can you explain at a deeper level what the property wrapper is actually doing when invoked? Is this basically equivalent to immediately calling a function on a new object? The thing I am finding hardest about Swift is that there is so much black-boxed "magic" scattered throughout the language. All these features exist that involve decorator keywords, so I end up writing code the 'hard' way because I simply don't know these features exist. Also, the part where you have to set a default value arbitrarily on the line where the property wrapper is invoked seems like it would be very unintuitive to someone else reading the code. I don't like how that looks - and it leads back to my trying to understand why the initializers requirements are the way they are in some of these examples.
The initializer is required any time you have an additional properties or if you are going to be transforming the wrappedValue. Since these are structs, we want to ensure that all properties are initialized. In my examples, the only time I do not have an initializer is when I am accessing the projected value (Example 1). In this case we do not need to initialize the wrapped value since it is never accessed, We only access the actual property and its projected value.
As for setting a default value, I agree that it is not intuitive, but it will be overridden anyway when an instance of the struct is initialized. PropertyWrappers are indeed a bit confusing. By the sounds of it, I have not done a particularly good job explaining them. I will see if I can put something else together in the future that will clarify more.
structs don't require an initializer unlike classes, however you can utilize an initializer for a struct if you need. In all of examples initializers are a must because you want your functionality to be implemented as soon properties get any value. Thus, if the author of the channel haven't used initializers for structs, he wouldn't have got the expected result on the property from the first initialization. Sound misleading , I know, but you have to practise to understand better. I , for one , always rewatch videos to get it. And that's no hard way, that's a necessity.
BTW, the explanation in the video is nearly flawless, if you find it too difficult , you should take easier classes. Perhaps that was not at your level .
I am reviewing this topic, so I can send you a simple repo if you really want to understand.