Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func testAssociation() {
- class Holder {}
- class Association {}
- var associationHolder: Holder? = Holder()
- var strongReferenceAssociation: Association? = Association()
- weak var weakReferenceAssociation: Association? = strongReferenceAssociation
- var associationKey = "key"
- objc_setAssociatedObject(associationHolder!, &associationKey, strongReferenceAssociation!, .OBJC_ASSOCIATION_RETAIN)
- weak var retrievedAssociation = objc_getAssociatedObject(associationHolder, &associationKey) as? Association
- XCTAssertTrue(strongReferenceAssociation! === retrievedAssociation!)
- strongReferenceAssociation = nil
- associationHolder = nil
- XCTAssertTrue(weakReferenceAssociation === .none)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement