Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- class ProductFactory {
- var items = 8
- }
- struct Product {
- let identifier: Int
- let name: String
- let inStock: Bool
- let factory = ProductFactory()
- }
- // To pass reference of `carToy` into `withUnsafePointer` you need to change let into var
- var productA = Product(identifier: 1234,
- name: "Remote car",
- inStock: true)
- withUnsafePointer(to: &productA) { print("Product A address \($0)") } // 0x00007ffee156bb90
- var productB = productA
- withUnsafePointer(to: &productB) { print("Product B address \($0)") } // 0x00007ffee156bb48
- // Let's create empty struct
- struct EmptyProduct {
- }
- var emptyProductStruct = EmptyProduct()
- withUnsafePointer(to: &emptyProductStruct) { print("Empty product address \($0)") } // 0x0000000128080880
- var emptyProductStructCopy = emptyProductStruct
- withUnsafePointer(to: &emptyProductStructCopy) { print("Empty product copy address \($0)") } // 0x0000000128080880
Add Comment
Please, Sign In to add comment