学习SwiftBond/Bond

2016-05-13  本文已影响323人  cocoaroger

github地址:https://github.com/SwiftBond/Bond

textField.bnd_text
.observe { text in print(text) }


textField.bnd_text
.bindTo(label.bnd_text)


textField.bnd_text
.map { "Hi " + $0 }
.bindTo(label.bnd_text)


button.bnd_controlEvent
.filter { $0 == UIControlEvents.TouchUpInside }
.observe { e in
print("Button tapped.")
}


button.bnd_tap
.observe {
print("Button tapped.")
}


combineLatest(emailField.bnd_text, passField.bnd_text)
.map { email, pass in
return email.length > 0 && pass.length > 0
}
.bindTo(button.bnd_enabled)


viewModel.numberOfFollowers
.map { "($0)" }
.bindTo(label.bnd_text)


viewModel.username.bidirectionalBindTo(usernameTextField.bnd_text)


NSNotificationCenter.defaultCenter().bnd_notification("MyNotification")
.observe { notification in
print("Got (notification)")
}
.disposeIn(bnd_bag)


repositories.bindTo(collectionView) { indexPath, array, collectionView in
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! RepositoryCell
let repository = array[indexPath.section][indexPath.item]
repository.name
.bindTo(cell.nameLabel.bnd_text)
.disposeIn(cell.onReuseBag)
repository.photo
.bindTo(cell.avatarImageView.bnd_image)
.disposeIn(cell.onReuseBag)
return cell
})

上一篇 下一篇

猜你喜欢

热点阅读