Created
September 10, 2017 07:24
-
-
Save multinerd/cb65a598435d8606bc523ee2dd2ebb8c to your computer and use it in GitHub Desktop.
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
// MARK: - UIView Extension for Dance | |
@available(iOS 10.0, *) | |
extension UIView { | |
fileprivate struct DanceAssociatedKey { | |
static var dance = "dance_key" | |
} | |
public var dance: Dance { | |
get { | |
if let danceInstance = objc_getAssociatedObject(self, &DanceAssociatedKey.dance) as? Dance { | |
return danceInstance | |
} else { | |
let newDanceInstance = Dance(dancingView: self) | |
objc_setAssociatedObject(self, &DanceAssociatedKey.dance, newDanceInstance, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN) | |
return newDanceInstance | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment