Created
March 10, 2020 06:05
-
-
Save perpeer/7fefde262a354cfc260bd76db9a73d06 to your computer and use it in GitHub Desktop.
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
| import UIKit | |
| final class Element { | |
| init() { | |
| print("Element init is called") | |
| } | |
| deinit { | |
| print("Element deinit is called") | |
| } | |
| } | |
| final class ArrayHandler { | |
| let array = [Element(), Element()] | |
| } | |
| final class Main { | |
| var slice: ArraySlice<Element> | |
| init() { | |
| let arrayHandler = ArrayHandler() | |
| slice = arrayHandler.array.dropLast() // `slice` holds a strong reference of `arrayHandler.array` | |
| } | |
| } | |
| var main = Main() | |
| main = Main() | |
| /* | |
| **Print** | |
| Element init is called | |
| Element init is called | |
| Element init is called | |
| Element init is called | |
| Element deinit is called | |
| Element deinit is called | |
| **Resource** | |
| Marcosantadev: https://marcosantadev.com/arrayslice-in-swift/ | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment