I’m looking for a more swifty way to do what the following iOS swift code does.
extension UITextField {
private static var NextFieldKey = "nextField"
@IBOutlet var nextField: UITextField? {
get {
return objc_getAssociatedObject(self, &UITextField.NextFieldKey) as? UITextField
}
set {
objc_setAssociatedObject(self, &UITextField.NextFieldKey, newValue, .OBJC_ASSOCIATION_ASSIGN)
}
}
}
class ViewController: UIViewController, UITextFieldDelegate {
func textFieldShouldReturn(textField: UITextField) -> Bool {
if let next = textField.nextField {
next.becomeFirstResponder()
} else {
textField.resignFirstResponder()
}
return true
}
}