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 👍
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.
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/RU-vid-tutorial/tree/master/CopyOnWrite Here's the discord invite link to iOS Cafe: discord.gg/gB3mhP8DNq
@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.
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.
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 !!
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).
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.