Skip to content

Instantly share code, notes, and snippets.

View taichino's full-sized avatar

Matsumoto Taichi taichino

View GitHub Profile
@taichino
taichino / test.swift
Created May 13, 2022 21:28
Observing an array test
import Combine
var list = ["A", "B", "C"]
let cancellable = list.publisher
.collect()
.sink { completion in
print("Completed with \(completion)")
} receiveValue: { value in
print(value)
}
package main
import "fmt"
func trace(msg string) string {
fmt.Printf("BEGIN %s\n", msg)
return msg
}
func untrace(msg string) string {
import UIKit
import RxSwift
import RxCocoa
class SimpleTableViewExampleViewController : ViewController, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
let itemsObservable = BehaviorRelay(value: (0..<5).map { "\($0)" })
@objc func add() {
SRKTransaction.transaction({
SharkUser.query().fetch().removeAll()
SharkCommit.query().fetch().removeAll()
}, withRollback: {})
try! realm.write {
realm.deleteAll()
}
for _ in [0...Globals.UPDATE_REPEAT] {
SRKTransaction.transaction({
self.commit.message = randomString(length: self.commit.message.characters.count)
self.commit.commit() // this happened to be confusing :P (commit object is committing the change)
}, withRollback: {})
}
for _ in [0...Globals.UPDATE_REPEAT] {
try! realm.write {
commit.message = randomString(length: commit.message.characters.count)
}
}
for _ in [0...Globals.RANDOM_SELECT_REPEAT] {
_ = realm.objects(RealmUser.self).filter("id = %@", user.id).first!.commits[Int(arc4random_uniform(UInt32(max)))]
}
for _ in [0...Globals.RANDOM_SELECT_REPEAT] {
let index = Int(arc4random_uniform(UInt32(max)))
_ = SharkCommit.query().where(withFormat: "user = %@", withParameters: [self.user]).fetch()[index]
}
for _ in [0...Globals.SELECT_COUNT_REPEAT] {
_ = SharkUser.query().fetch().count
}