NxEnabled 1.1.1

NxEnabled 1.1.1

TestsTested โœ“
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Mar 2017
SwiftSwift Version 3.0
SPMSupports SPM โœ“

Maintained by Nikita Ermolenko.



NxEnabled 1.1.1

  • By
  • Nikita Ermolenko

NxEnabled

What is NxEnabled?

Itโ€™s a fairly common case, when the enabled state of button depends on some textable elements such as TextView, TextField. So this library allows the simplest way to achive this purpose with only few lines of code.

Getting started ๐Ÿš€

Typical login screen with short, beautiful validation code:

loginButton.isEnabled(by: usernameTextField, passwordTextField) { username, password in
    username.characters.count > 5 && password.characters.count > 5
}

you can also combine together UITextView with UITextFieldโ€™s:

signUpButton.isEnabled(by: firstnameTextField, lastnameTextField, bioTextView) { firstname, lastname, bio in
    return /* validation value */
}

So there is also oportunity to add not UI element:

  • Implement Textable protocol

  • Be a successor from NSObject

  • Not forget about dynamic label for property

  • Done.

class Object: NSObject, Textable {
    dynamic var value: String?
    var textKey: String {
        return "value"
    }
}

NOTE:

One important case is that you should clear buttonโ€™s bag. It removes all observers from textable elements. Usually it needs to do in deinit method.

deinit {
    signUpButton.clearBag()
}

Now library allows to add textable elements up to six. ๐Ÿ‘

Author ๐Ÿ’ช

Nikita Ermolenko, [email protected]

License โ—๏ธ

NxEnabled is available under the MIT license. See the LICENSE file for more info.