Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save creaaa/39abff9d17c5de67987b358f11dce3ea to your computer and use it in GitHub Desktop.
Save creaaa/39abff9d17c5de67987b358f11dce3ea to your computer and use it in GitHub Desktop.
bossの中のmap(Cold)は、3箇所から購読されてるので3回読まれているが、subscribe onNextの中("hogehoge1"とか)は、それぞれ1回しか実行されないぞ。当たり前かもだが。
let boss = self.tfBoss.rx.text
.map { text -> String in
print("はいきた")
let t = text ?? ""
return t
}
boss.subscribe(onNext: { text in
print("hogehoge1")
self.tf1.text = text
})
boss.subscribe(onNext: { text in
print("hogehoge2")
self.tf2.text = text
})
boss.subscribe(onNext: { text in
print("hogehoge3")
self.tf3.text = text
})
// 結果
はいきた
hogehoge1
はいきた
hogehoge2
はいきた
hogehoge3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment