-
I'm currently in the process of migrating to 1.7, but faced the challenge of the title. override func viewDidLoad() {
setupObservers()
}
private func setupObservers() {
observeAppearance()
observeLogin()
// ...
}
private func observeAppearance() {
store.publisher.appearance.sink {
// ....
}
}
private func observeLogin() {
store.scope(
state: \.login,
action: \.login
).ifLet {
// ...
}
}
// ... I'm replacing these API with For instance, should one override func viewDidLoad() {
observe { [weak self] in
guard let self else { return }
observeAppearance()
observeLogin()
// ...
}
}
private func observeAppearance() {
let appearance = store.appearance
// ....
}
private func observeLogin() {
if let loginStore = store.scope(state: \.login, action: \.login) {
// ...
}
}
// ... Or should we use multiple override func viewDidLoad() {
observeAppearance()
observeLogin()
}
private func observeAppearance() {
observe { [weak self] in
guard let self else { return }
let appearance = store.appearance
// ....
}
}
private func observeLogin() {
observe { [weak self] in
guard let self else { return }
if let loginStore = store.scope(state: \.login, action: \.login) {
// ...
}
}
}
// ... |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
I had this question as well as I was migrating my UIKit codebase to using the new Observability framework. What Brandon had told me is that in general, you should be safe to add everything in a single |
Beta Was this translation helpful? Give feedback.
Hi @y-mimura, while it is completely fine to split out into multiple
observe
s, it is also possible to put it in one and do navigation. Our TicTacToe demo shows how to do this:swift-composable-architecture/Examples/TicTacToe/tic-tac-toe/Sources/LoginUIKit/LoginViewController.swift
Lines 102 to 123 in 4c6b617