Commit aad07d33 by Daniel Dahan

updated associated objects

parent d1f68623
...@@ -276,12 +276,12 @@ public extension UITabBar { ...@@ -276,12 +276,12 @@ public extension UITabBar {
/// TabBarItem reference. /// TabBarItem reference.
public internal(set) var item: MaterialAssociatedObjectTabBar { public internal(set) var item: MaterialAssociatedObjectTabBar {
get { get {
return MaterialAssociatedObject(self, key: &MaterialAssociatedObjectTabBarKey) { return associatedObject(self, key: &MaterialAssociatedObjectTabBarKey) {
return MaterialAssociatedObjectTabBar(depth: .None) return MaterialAssociatedObjectTabBar(depth: .None)
} }
} }
set(value) { set(value) {
MaterialAssociateObject(self, key: &MaterialAssociatedObjectTabBarKey, value: value) associateObject(self, key: &MaterialAssociatedObjectTabBarKey, value: value)
} }
} }
......
...@@ -244,12 +244,12 @@ public extension UIView { ...@@ -244,12 +244,12 @@ public extension UIView {
/// Grid reference. /// Grid reference.
public private(set) var grid: Grid { public private(set) var grid: Grid {
get { get {
return MaterialAssociatedObject(self, key: &GridKey) { return associatedObject(self, key: &GridKey) {
return Grid() return Grid()
} }
} }
set(value) { 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 { ...@@ -908,12 +908,12 @@ public extension UIView {
/// Layout reference. /// Layout reference.
public private(set) var layout: Layout { public private(set) var layout: Layout {
get { get {
return MaterialAssociatedObject(self, key: &LayoutKey) { return associatedObject(self, key: &LayoutKey) {
return Layout(parent: self) return Layout(parent: self)
} }
} }
set(value) { set(value) {
MaterialAssociateObject(self, key: &LayoutKey, value: value) associateObject(self, key: &LayoutKey, value: value)
} }
} }
......
...@@ -29,29 +29,29 @@ ...@@ -29,29 +29,29 @@
*/ */
/** /**
Gets the Obj-C reference for the Grid object within the UIView extension. Gets the Obj-C reference for the instance object within the UIView extension.
- Parameter base: Base object. - Parameter base: Base object.
- Parameter key: Memory key pointer. - Parameter key: Memory key pointer.
- Parameter initializer: Object initializer. - Parameter initializer: Object initializer.
- Returns: The associated reference for the initializer object. - Returns: The associated reference for the initializer object.
*/ */
public func MaterialAssociatedObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, initializer: () -> T) -> T { internal func associatedObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, initializer: () -> T) -> T {
if let v: T = objc_getAssociatedObject(base, key) as? T { if let v: T = objc_getAssociatedObject(base, key) as? T {
return v return v
} }
let v: T = initializer() let v: T = initializer()
objc_setAssociatedObject(base, key, v, .OBJC_ASSOCIATION_RETAIN) objc_setAssociatedObject(base, key, v, .OBJC_ASSOCIATION_RETAIN)
return v return v
} }
/** /**
Sets the Obj-C reference for the Grid object within the UIView extension. Sets the Obj-C reference for the instance object within the UIView extension.
- Parameter base: Base object. - Parameter base: Base object.
- Parameter key: Memory key pointer. - Parameter key: Memory key pointer.
- Parameter value: The object instance to set for the associated object. - Parameter value: The object instance to set for the associated object.
- Returns: The associated reference for the initializer object. - Returns: The associated reference for the initializer object.
*/ */
public func MaterialAssociateObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, value: T) { internal func associateObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, value: T) {
objc_setAssociatedObject(base, key, value, .OBJC_ASSOCIATION_RETAIN) objc_setAssociatedObject(base, key, value, .OBJC_ASSOCIATION_RETAIN)
} }
\ No newline at end of file
...@@ -83,12 +83,12 @@ public extension UINavigationItem { ...@@ -83,12 +83,12 @@ public extension UINavigationItem {
/// NavigationItem reference. /// NavigationItem reference.
public internal(set) var item: MaterialAssociatedObjectNavigationItem { public internal(set) var item: MaterialAssociatedObjectNavigationItem {
get { get {
return MaterialAssociatedObject(self, key: &MaterialAssociatedObjectNavigationItemKey) { return associatedObject(self, key: &MaterialAssociatedObjectNavigationItemKey) {
return MaterialAssociatedObjectNavigationItem() return MaterialAssociatedObjectNavigationItem()
} }
} }
set(value) { 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