Last active
April 2, 2024 13:42
-
-
Save nicholascross/8285cef20b1f5f171557478647cc0cdd to your computer and use it in GitHub Desktop.
Revisions
-
nicholascross renamed this gist
Feb 9, 2019 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
nicholascross created this gist
Feb 9, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ class Example { } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ struct WeakBox<ItemType: AnyObject> { weak var item: ItemType? init(item: ItemType?) { self.item = item } } 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ // // WeakBox.swift // Injectable // // Created by Nicholas Cross on 9/2/19. // Copyright © 2019 Nicholas Cross. All rights reserved. // import XCTest class WeakBoxExampleTests: XCTestCase { func testWeakDictionary() { var weakDictionary: [String: WeakBox<Example>] = [:] var example: Example? = Example() weakDictionary["example"] = WeakBox(item:example) XCTAssertNotNil(weakDictionary["example"]?.item) example = nil XCTAssertNil(weakDictionary["example"]?.item) } }