Guest User

Untitled

a guest
May 23rd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. import Foundation
  2.  
  3. class ProductFactory {
  4. var items = 8
  5. }
  6.  
  7. struct Product {
  8. let identifier: Int
  9. let name: String
  10. let inStock: Bool
  11. let factory = ProductFactory()
  12. }
  13.  
  14. // To pass reference of `carToy` into `withUnsafePointer` you need to change let into var
  15. var productA = Product(identifier: 1234,
  16. name: "Remote car",
  17. inStock: true)
  18.  
  19. withUnsafePointer(to: &productA) { print("Product A address \($0)") } // 0x00007ffee156bb90
  20.  
  21. var productB = productA
  22.  
  23. withUnsafePointer(to: &productB) { print("Product B address \($0)") } // 0x00007ffee156bb48
  24.  
  25. // Let's create empty struct
  26. struct EmptyProduct {
  27. }
  28.  
  29. var emptyProductStruct = EmptyProduct()
  30.  
  31. withUnsafePointer(to: &emptyProductStruct) { print("Empty product address \($0)") } // 0x0000000128080880
  32.  
  33. var emptyProductStructCopy = emptyProductStruct
  34.  
  35. withUnsafePointer(to: &emptyProductStructCopy) { print("Empty product copy address \($0)") } // 0x0000000128080880
Add Comment
Please, Sign In to add comment