Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mpon/swiftbonddemo
SwiftBond/Bond demo
https://github.com/mpon/swiftbonddemo
Last synced: 3 months ago
JSON representation
SwiftBond/Bond demo
- Host: GitHub
- URL: https://github.com/mpon/swiftbonddemo
- Owner: mpon
- License: mit
- Created: 2015-02-04T09:41:52.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2015-08-12T02:10:38.000Z (over 9 years ago)
- Last Synced: 2023-08-05T05:51:42.345Z (over 1 year ago)
- Language: Swift
- Homepage: https://github.com/SwiftBond/Bond
- Size: 1.05 MB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[SwiftBond/Bond](https://github.com/SwiftBond/Bond) Demo
=====UITextField and UISlider
---### About
![demo1](demo1.gif)
### Code
```swift
override func viewDidLoad() {
super.viewDidLoad()// UITextField
textField ->> textLabel// UISlider
slider
.valueDynamic()
.map({"Hi, my value is \($0)"})
->> sliderLabel
}
```Validation
---### About
This is the common example of validating a signup form.
- rule1: you are able to push the button, to satisfy the follwing conditions.
1. username and email are not empty.
2. password and password confirmation are equal.
3. password length is more than 8 characters.
- rule2: if password and password confirmation are different, output error message.![demo2](demo2.gif)
### Code
```swift
override func viewDidLoad() {
super.viewDidLoad()// designate text dynamic
let username = usernameField.textDynamic()
let email = usernameField.textDynamic()
let password = passwordField.textDynamic()
let passwordConfirm = passwordConfirmField.textDynamic()// ============= rule1 =============
let rule1a = reduce(username, email, false) { !($0.isEmpty || $1.isEmpty) }
let rule1b = reduce(password, passwordConfirm, false) { $0 == $1 }
let rule1c = password.map { countElements($0) >= 8 }
reduce(rule1a, rule1b, rule1c, false) { $0 && $1 && $2 } ->> createButton// ============= rule2 =============
reduce(password, passwordConfirm, "") {
$0 == $1 ? "" : "The password does not match"
} ->> errorLabel}
```Getting Started
-----```
$ git clone https://github.com/mpon/SwiftBondDemo.git
$ bundle install --path=vendor/bundle
$ bundle exec pod install
$ open SwiftBondDemo.xcworkspace
```