Last active
December 26, 2025 07:03
-
-
Save Roshankumar350/1b0111ae4978920fbfeefb7518d20fe5 to your computer and use it in GitHub Desktop.
Copy on write:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Person { | |
| var name: String | |
| init(name: String) { | |
| self.name = name | |
| } | |
| } | |
| let person1 = Person(name: "Mike") | |
| let person2 = person1 | |
| let address1 = Unmanaged.passUnretained(person1).toOpaque() | |
| let address2 = Unmanaged.passUnretained(person2).toOpaque() | |
| // Both are same | |
| print("Person1: \(address1)") | |
| print("Person2: \(address2)") | |
| struct Animal { | |
| var name: String | |
| } | |
| var animal1 = Animal(name: "Tiger") | |
| var animal2 = animal1 | |
| // Both are not same | |
| withUnsafeBytes(of: &animal1) { pointer in | |
| print("Animal1: \(pointer)") | |
| } | |
| withUnsafeBytes(of: &animal2) { pointer in | |
| print("Animal2: \(pointer)") | |
| } |
Author
Roshankumar350
commented
Dec 25, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment