diff --git a/MulticastDelegateDemo/DemoService.swift b/MulticastDelegateDemo/DemoService.swift index 61a29a2..381e62a 100644 --- a/MulticastDelegateDemo/DemoService.swift +++ b/MulticastDelegateDemo/DemoService.swift @@ -7,6 +7,7 @@ // import Foundation +import MulticastDelegateDemo protocol DemoServiceDelegate { diff --git a/MulticastDelegateDemoTests/MulticastDelegateDemoTests.swift b/MulticastDelegateDemoTests/MulticastDelegateDemoTests.swift index f964214..84c8d9b 100644 --- a/MulticastDelegateDemoTests/MulticastDelegateDemoTests.swift +++ b/MulticastDelegateDemoTests/MulticastDelegateDemoTests.swift @@ -275,7 +275,7 @@ class MulticastDelegateDemoTests: XCTestCase { XCTAssertTrue(multicastDelegate.containsDelegate(delegate)) } - + func testContainsDelegateNeverAddedDelegateReturnsFalse() { let multicastDelegate = MulticastDelegate() @@ -283,39 +283,60 @@ class MulticastDelegateDemoTests: XCTestCase { XCTAssertFalse(multicastDelegate.containsDelegate(delegate)) } - + func testEmptyAfterCreation() { let multicastDelegate = MulticastDelegate() XCTAssertTrue(multicastDelegate.isEmpty) } - - func testNotEmptyAfterAdd() { + + func testNotEmptyAfterAddStrongReference() { let multicastDelegate = MulticastDelegate() - multicastDelegate += DelegateTestClass() - + let delegate1 = DelegateTestClass() + multicastDelegate += delegate1 + XCTAssertFalse(multicastDelegate.isEmpty) } - - func testNotEmptyAfterDoubleAdd() { - + + func testNotEmptyAfterDoubleAddStrongReferences() { + + let multicastDelegate = MulticastDelegate() + let delegate1 = DelegateTestClass() + let delegate2 = DelegateTestClass() + multicastDelegate += delegate1 + multicastDelegate += delegate2 + + XCTAssertFalse(multicastDelegate.isEmpty) + } + + // Thank you ARC + Weak References + func testEmptyAfterAddWeakReference() { + let multicastDelegate = MulticastDelegate() multicastDelegate += DelegateTestClass() + + XCTAssertTrue(multicastDelegate.isEmpty) + } + + func testEmptyAfterDoubleAddWeakReferences() { + + let multicastDelegate = MulticastDelegate() multicastDelegate += DelegateTestClass() - - XCTAssertFalse(multicastDelegate.isEmpty) + multicastDelegate += DelegateTestClass() + + XCTAssertTrue(multicastDelegate.isEmpty) } func testEmptyAfterAddAndDelete() { - + let multicastDelegate = MulticastDelegate() let delegate = DelegateTestClass() multicastDelegate += delegate multicastDelegate -= delegate - + XCTAssertTrue(multicastDelegate.isEmpty) } - + }