Commit aad07d33 by Daniel Dahan

updated associated objects

parent d1f68623
......@@ -276,12 +276,12 @@ public extension UITabBar {
/// TabBarItem reference.
public internal(set) var item: MaterialAssociatedObjectTabBar {
get {
return MaterialAssociatedObject(self, key: &MaterialAssociatedObjectTabBarKey) {
return associatedObject(self, key: &MaterialAssociatedObjectTabBarKey) {
return MaterialAssociatedObjectTabBar(depth: .None)
}
}
set(value) {
MaterialAssociateObject(self, key: &MaterialAssociatedObjectTabBarKey, value: value)
associateObject(self, key: &MaterialAssociatedObjectTabBarKey, value: value)
}
}
......
......@@ -244,12 +244,12 @@ public extension UIView {
/// Grid reference.
public private(set) var grid: Grid {
get {
return MaterialAssociatedObject(self, key: &GridKey) {
return associatedObject(self, key: &GridKey) {
return Grid()
}
}
set(value) {
MaterialAssociateObject(self, key: &GridKey, value: value)
associateObject(self, key: &GridKey, value: value)
}
}
}
\ No newline at end of file
......@@ -908,12 +908,12 @@ public extension UIView {
/// Layout reference.
public private(set) var layout: Layout {
get {
return MaterialAssociatedObject(self, key: &LayoutKey) {
return associatedObject(self, key: &LayoutKey) {
return Layout(parent: self)
}
}
set(value) {
MaterialAssociateObject(self, key: &LayoutKey, value: value)
associateObject(self, key: &LayoutKey, value: value)
}
}
......
......@@ -29,29 +29,29 @@
*/
/**
Gets the Obj-C reference for the Grid object within the UIView extension.
- Parameter base: Base object.
- Parameter key: Memory key pointer.
- Parameter initializer: Object initializer.
- Returns: The associated reference for the initializer object.
*/
public func MaterialAssociatedObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, initializer: () -> T) -> T {
if let v: T = objc_getAssociatedObject(base, key) as? T {
return v
}
let v: T = initializer()
objc_setAssociatedObject(base, key, v, .OBJC_ASSOCIATION_RETAIN)
return v
Gets the Obj-C reference for the instance object within the UIView extension.
- Parameter base: Base object.
- Parameter key: Memory key pointer.
- Parameter initializer: Object initializer.
- Returns: The associated reference for the initializer object.
*/
internal func associatedObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, initializer: () -> T) -> T {
if let v: T = objc_getAssociatedObject(base, key) as? T {
return v
}
let v: T = initializer()
objc_setAssociatedObject(base, key, v, .OBJC_ASSOCIATION_RETAIN)
return v
}
/**
Sets the Obj-C reference for the Grid object within the UIView extension.
- Parameter base: Base object.
- Parameter key: Memory key pointer.
- Parameter value: The object instance to set for the associated object.
- Returns: The associated reference for the initializer object.
*/
public func MaterialAssociateObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, value: T) {
objc_setAssociatedObject(base, key, value, .OBJC_ASSOCIATION_RETAIN)
Sets the Obj-C reference for the instance object within the UIView extension.
- Parameter base: Base object.
- Parameter key: Memory key pointer.
- Parameter value: The object instance to set for the associated object.
- Returns: The associated reference for the initializer object.
*/
internal func associateObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, value: T) {
objc_setAssociatedObject(base, key, value, .OBJC_ASSOCIATION_RETAIN)
}
\ No newline at end of file
......@@ -83,12 +83,12 @@ public extension UINavigationItem {
/// NavigationItem reference.
public internal(set) var item: MaterialAssociatedObjectNavigationItem {
get {
return MaterialAssociatedObject(self, key: &MaterialAssociatedObjectNavigationItemKey) {
return associatedObject(self, key: &MaterialAssociatedObjectNavigationItemKey) {
return MaterialAssociatedObjectNavigationItem()
}
}
set(value) {
MaterialAssociateObject(self, key: &MaterialAssociatedObjectNavigationItemKey, value: value)
associateObject(self, key: &MaterialAssociatedObjectNavigationItemKey, value: value)
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment