Skip to content

Instantly share code, notes, and snippets.

@yoonchulkoh
Created December 8, 2016 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yoonchulkoh/2134466169b050e272bf8ee1d2a847a9 to your computer and use it in GitHub Desktop.
Save yoonchulkoh/2134466169b050e272bf8ee1d2a847a9 to your computer and use it in GitHub Desktop.
Usage Bond batchUpdate
import UIKit
import Bond
class ViewController: UIViewController {
let items: MutableObservableArray<String> = MutableObservableArray<String>([])
override func viewDidLoad() {
super.viewDidLoad()
var batchBeginning = false
_ = items.skip(first: 1).observeNext { (items) in
let block = {
debugPrint("change: \(items.change), items: \(self.items.array)")
debugPrint("refresh実行")
}
switch items.change {
case .beginBatchEditing:
batchBeginning = true
case .endBatchEditing:
block()
batchBeginning = false
default:
if !batchBeginning {
block()
}
}
}
debugPrint("=== 通常実行 ===")
items.append("a")
debugPrint("=== バッチ実行 ===")
items.batchUpdate { (a) in
a.append("1")
a.append("2")
a.append("3")
}
}
}
"=== 通常実行 ==="
"change: inserts([0]), items: [\"a\"]"
"refresh実行"
"=== バッチ実行 ==="
"change: endBatchEditing, items: [\"a\", \"1\", \"2\", \"3\"]"
"refresh実行"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment