     /// The closure to be called to determine whether the chracters in the text field should change.
     var shouldChangeCharactersClosure: TextFieldChangeCharacters? {
         get {
-            return objc_getAssociatedObject(self, AssociatedKeys.textFieldShouldChangeCharactersHandle) as? TextFieldChangeCharacters
-        }
-        set {
-            objc_setAssociatedObject(self, AssociatedKeys.textFieldShouldChangeCharactersHandle, (newValue as! AnyObject!), .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
-            manageDelegate()
-        }
-    }
-
+            guard let boxedValue = objc_getAssociatedObject(self, AssociatedKeys.textFieldShouldChangeCharactersHandle) as? Box<TextFieldChangeCharacters> else { return nil }
+            return boxedValue.value
+        }
+        set {
+            let boxedValue: Box<TextFieldChangeCharacters>? = newValue != nil ? Box(value: newValue!) : nil
+            objc_setAssociatedObject(self, AssociatedKeys.textFieldShouldChangeCharactersHandle, boxedValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
+            manageDelegate()
+        }
+    }
+    
     /// The closure to be called to determine whether the text field should clear.
     var shouldClearClosure: TextFieldResponse? {
         get {
-            return objc_getAssociatedObject(self, AssociatedKeys.textFieldShouldClearHandle) as? TextFieldResponse
-        }
-        set {
-            objc_setAssociatedObject(self, AssociatedKeys.textFieldShouldClearHandle, (newValue as! AnyObject!), .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
+            guard let boxedValue = objc_getAssociatedObject(self, AssociatedKeys.textFieldShouldClearHandle) as? Box<TextFieldResponse> else { return nil }
+            return boxedValue.value
+        }
+        set {
+            let boxedValue: Box<TextFieldResponse>? = newValue != nil ? Box(value: newValue!) : nil
+            objc_setAssociatedObject(self, AssociatedKeys.textFieldShouldClearHandle, boxedValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
             manageDelegate()
         }
     }
     /// The closure to be called to determine whether the text field should return.
     var shouldReturnClosure: TextFieldResponse? {
         get {
-            return objc_getAssociatedObject(self, AssociatedKeys.textFieldShouldReturnHandle) as? TextFieldResponse
-        }
-        set {
-            objc_setAssociatedObject(self, AssociatedKeys.textFieldShouldReturnHandle, (newValue as! AnyObject!), .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
+            guard let boxedValue = objc_getAssociatedObject(self, AssociatedKeys.textFieldShouldReturnHandle) as? Box<TextFieldResponse> else { return nil }
+            return boxedValue.value
+        }
+        set {
+            let boxedValue: Box<TextFieldResponse>? = newValue != nil ? Box(value: newValue!) : nil
+            objc_setAssociatedObject(self, AssociatedKeys.textFieldShouldReturnHandle, boxedValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
             manageDelegate()
         }
     }

import UIKit
import ObjectiveC

//	MARK: UITextField Closures Extension

/**
    `UITextField`

    This extension to UITextField adds the ability to assign closures to what would usually need to be delegate methods.
 */
public extension UITextField {
    
    //	MARK: Associated Keys Struct
    

    /// The closure to be called when the text field did begin editing.
    var didBeginEditingClosure: TextFieldAction? {
        get {
            guard let boxedValue = objc_getAssociatedObject(self, AssociatedKeys.textFieldDidBeginEditingHandle) as? Box<TextFieldAction> else { return nil }
            return boxedValue.value
        }
        set {
            let boxedValue: Box<TextFieldAction>? = newValue != nil ? Box(value: newValue!) : nil
            objc_setAssociatedObject(self, AssociatedKeys.textFieldDidBeginEditingHandle, boxedValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
            manageDelegate()
        }
    }
    
    /// The closure to be called when the text field end begin editing.
    var didEndEditingClosure: TextFieldAction? {
        get {
            guard let boxedValue = objc_getAssociatedObject(self, AssociatedKeys.textFieldDidEndEditingHandle) as? Box<TextFieldAction> else { return nil }
            return boxedValue.value
        }
        set {
            let boxedValue: Box<TextFieldAction>? = newValue != nil ? Box(value: newValue!) : nil
            objc_setAssociatedObject(self, AssociatedKeys.textFieldDidEndEditingHandle, boxedValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
            manageDelegate()
        }
    }
