Pretty interesting how such minor details are being taken care of when it comes to memory management, indeed this topic is very interesting and an interviewer favorite question.
You are doing great job sir. I have never seen any youtuber who is doing such a hard word to create quality videos. Thanks a lot for this channel, please keep it alive.
For let and var question, I think we have to change let to var because struct are immutable type so we need to change it. Like we use mutating in stuct for modifications. Thanks bro for this video 👍
Hey there, I hope this video was helpful. The code shown in the video is uploaded on GitHub, given is the link for the same. GitHub link: github.com/codecat15/CZcams-tutorial/tree/master/CopyOnWrite Here's the discord invite link to iOS Cafe: discord.gg/gB3mhP8DNq
Thank you for explaining the COW concept. 4:09 Answer (As per my understanding) "let" is used for constant only, as we are changing/modifying the "car2" property "name", so we need to use "var" there.
@@CodeCat15 Class:- with let cause, "class" is considered as "constant of address". It can not be reassigned but can be changed. The property should be with "var" too. Like if we change "var name: String" with "let name: String" then it will not work with the class too. Struct:- with let cause, it's considered as "constant of value". It is immutable (not modifiable).
Hi Nice video but I have one query you told reference type doesn't support COW... but in video 9:58 you explained example of COW with class(reference type)
Good observation Pavan and thank you for asking this question. The memory address that you see on the console are of arr1 and arr2 variables which are arrays and arrays are value types not reference types The code change at the mentioned time was to prove that the behavior of COW is not dependent on the elements of the array but the array itself. Does that answer your question? If not please feel free to ask more questions.
Class use same memory address that's why they are mutable and value can be modified even we are using let. But in case of struct they share different memory address, it means if you are using let and assigned some value and again you are going to change value it will throw error because you cannot modify value because it share different memory address and it store the previous value also. I think that's why structure are immutable. But in case of class it is mutable because they share same memory address and if we modify the value it means the previous value will be replaced with updated value. It means that the previous value is no longer exist and it behaves like you have not assigned any value earlier. I hope I have explained clearly.
And that’s what copy on write is, before change both will point to the same address and after the change the object that you changed will point to a different address
Amazing work .truly very well explanations as well as the mind of teaching skill you have is just FANTASTIC !!! , would request please become the "Hacking with Swift " of INDIA , and maintain the same quality as well as the content >>> only love !!
@code Cat answer: we are making mutable to change value from structure if have calass then no need to do this because class already have refrence type.
Amazing topic to discover.... Great work Ravi ....
Pretty interesting how such minor details are being taken care of when it comes to memory management, indeed this topic is very interesting and an interviewer favorite question.
You are doing great job sir. I have never seen any youtuber who is doing such a hard word to create quality videos. Thanks a lot for this channel, please keep it alive.
Thank you for your kind words Jay, I'll try my best to deliver more quality driven video. Thank you once again.
@@CodeCat15 Ab is se jyda bhi quality video ho sakta hai kya 😀
Koshish kar k dekhta hu, shayad thoda aur improve kar pau khud ko, there’s always room for improvement 😊
For let and var question, I think we have to change let to var because struct are immutable type so we need to change it.
Like we use mutating in stuct for modifications.
Thanks bro for this video 👍
Excellent explanation Narayan 👍 thank you for your answer
This is amazing Ravi Bhai ❤❤❤ very concise and to the point 👏
Thanks Junaid, I am glad this was helpful session.
Hey there, I hope this video was helpful. The code shown in the video is uploaded on GitHub, given is the link for the same.
GitHub link: github.com/codecat15/CZcams-tutorial/tree/master/CopyOnWrite
Here's the discord invite link to iOS Cafe: discord.gg/gB3mhP8DNq
Hi Bro, Amazing explanation, you are providing very valuable knowledge. Keep it up !
I am glad this was helpful, please feel free to ask questions on the topic and do share the channel with your iOS group
Thank you for explaining the COW concept.
4:09 Answer (As per my understanding)
"let" is used for constant only, as we are changing/modifying the "car2" property "name", so we need to use "var" there.
but the let did work when we were using a class so why did the compiler time error only arise during struct and not class?
@@CodeCat15
Class:-
with let cause, "class" is considered as "constant of address". It can not be reassigned but can be changed. The property should be with "var" too. Like if we change "var name: String" with "let name: String" then it will not work with the class too.
Struct:-
with let cause, it's considered as "constant of value". It is immutable (not modifiable).
Thank you Umair for this explanation, and well said 👍
@@CodeCat15 Thanks Ravi for counter questions.You always respond to comment section of your video.👍👍💓
Great explanation as usual!
Thank you Arif, am glad it was helpful
Amazing explanation 🙏
glad it was helpful
Hi Nice video
but I have one query you told reference type doesn't support COW... but in video 9:58 you explained example of COW with class(reference type)
Good observation Pavan and thank you for asking this question.
The memory address that you see on the console are of arr1 and arr2 variables which are arrays and arrays are value types not reference types
The code change at the mentioned time was to prove that the behavior of COW is not dependent on the elements of the array but the array itself.
Does that answer your question? If not please feel free to ask more questions.
@@CodeCat15 yes got it now
Thank you for answering
Keep posting
Thats great explanation Ravi, thanks you for sharing your quality knowledge !!
Glad you liked it! please feel free to ask question on this topic and do share the content with your ios group
@@CodeCat15 sure Ravi I will
Amazing knowledge sharing!👍
Glad it was helpful 😊
@@CodeCat15 yes definitely it is, and keep up the good work with quality, all the very best!👍
thanks much for sharing 🙏🏻
My pleasure, glad to know this video was helpful 😊 please feel free to ask questions on the topic and do share the video with your iOS group
Class use same memory address that's why they are mutable and value can be modified even we are using let. But in case of struct they share different memory address, it means if you are using let and assigned some value and again you are going to change value it will throw error because you cannot modify value because it share different memory address and it store the previous value also. I think that's why structure are immutable. But in case of class it is mutable because they share same memory address and if we modify the value it means the previous value will be replaced with updated value. It means that the previous value is no longer exist and it behaves like you have not assigned any value earlier. I hope I have explained clearly.
Thanks Jay for providing a detailed answer, good job.
Simple and straightforward!
Thank you for this video.
Thank you Abhishek 😊 feel free to ask questions on the topic
Good explanation
but the address after change in object is different in both types ... @9:05
And that’s what copy on write is, before change both will point to the same address and after the change the object that you changed will point to a different address
Amazing work .truly very well explanations as well as the mind of teaching skill you have is just FANTASTIC !!! , would request please become the "Hacking with Swift " of INDIA , and maintain the same quality as well as the content >>> only love !!
@code Cat answer: we are making mutable to change value from structure if have calass then no need to do this because class already have refrence type.
Good answer Hafiz 😊
I was waited for this.!!
Thanks Brother for this easy context❤️
Hope the video answers all your doubts regarding the topic, if not please ask questions in comment or on iOS cafe 😊
Beacuse you are changing the name car in car 2 instance but you take variable let in car2which is constant that’s why it is showing error.