Last active
October 9, 2015 12:08
-
-
Save eldesperado/f6a632ac0d98c39281e3 to your computer and use it in GitHub Desktop.
Stored Property in Swift Extension
This file contains 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 ObjectiveC | |
// Declare a global var to produce a unique address as the assoc object handle | |
var AssociatedObjectHandle: UInt8 = 0 | |
extension CCNode { | |
var previousX: CGFloat? { | |
get { | |
return objc_getAssociatedObject(self, &AssociatedObjectHandle) as? CGFloat | |
} | |
set { | |
objc_setAssociatedObject(self, &AssociatedObjectHandle, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) | |
} | |
} | |
var previousY: CGFloat? { | |
get { | |
return objc_getAssociatedObject(self, &AssociatedObjectHandle) as? CGFloat | |
} | |
set { | |
objc_setAssociatedObject(self, &AssociatedObjectHandle, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment