Last active
March 31, 2016 20:50
-
-
Save sferrini/a15b853c1f1ed65dad4ef82e3d8d08ac to your computer and use it in GitHub Desktop.
Revisions
-
sferrini revised this gist
Mar 31, 2016 . 1 changed file with 14 additions and 11 deletions.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 @@ -1,47 +1,50 @@ //: Playground - noun: a place where people can play typealias CompletionBlock = (Bool) -> () class BlockStorage { var blocks = [CompletionBlock]() func addBlock(block: CompletionBlock) { blocks.append(block) } deinit { print("BlockStorage deinit") } } class Client { var blockStorage = BlockStorage() func start() { blockStorage.addBlock() { [unowned self](success: Bool) in print("\(self) First block") } blockStorage.addBlock() { [unowned self](success: Bool) in self.doSomeThing(success) } } func doSomeThing(success: Bool) { print("Do Something") } deinit { print("Client deinit") } } func playground() { let client = Client() client.start() } playground() -
ignazioc revised this gist
Mar 31, 2016 . 1 changed file with 5 additions and 4 deletions.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 @@ -21,11 +21,12 @@ class Client { var blockStorage :BlockStorage = BlockStorage() func start() { blockStorage.addBlock() { [unowned self](success: Bool) in print("\(self) First block") } // blockStorage.addBlock(doSomeThing) //if this line is uncommented the Client and the BlockStorage are not deallocated. } func doSomeThing(param: Bool) { @@ -43,4 +44,4 @@ func playground() { } playground() -
ignazioc created this gist
Mar 31, 2016 .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,46 @@ //: Playground - noun: a place where people can play var str = "Hello, world" typealias CompletionBlock = (Bool) -> () class BlockStorage { var blocks :[CompletionBlock] = [] func addBlock(block: CompletionBlock) { blocks.append(block) } deinit { print("BlockStorage deallocated") } } class Client { var blockStorage :BlockStorage = BlockStorage() func start() { blockStorage.addBlock() { (success: Bool) in print("First block") } blockStorage.addBlock(doSomeThing) //if this line is uncommented the Client and the BlockStorage are not deallocated. } func doSomeThing(param: Bool) { print("Do Something") } deinit { print("Client Deallocated") } } func playground() { let client = Client() client.start() } playground()