Created
December 8, 2016 07:16
-
-
Save yoonchulkoh/2134466169b050e272bf8ee1d2a847a9 to your computer and use it in GitHub Desktop.
Usage Bond batchUpdate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"=== 通常実行 ===" | |
"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