Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StateObject(SwiftUI)とVIPERの相性の再検討 #14

Closed
shin-carpediem opened this issue Feb 8, 2023 · 1 comment
Closed

StateObject(SwiftUI)とVIPERの相性の再検討 #14

shin-carpediem opened this issue Feb 8, 2023 · 1 comment
Assignees
Labels
problem Not bug but troublesome issue

Comments

@shin-carpediem
Copy link
Owner

shin-carpediem commented Feb 8, 2023

Perspective

  • ObservedObject release when the parent objects get released, then it seems not secure to use ObservedObject as default.
  • StateObject seems a better choice.
  • Then, how to apply StateObject for VIPER's Presenter between ViewModel, and also, still should separate Interactor with Presenter?
@shin-carpediem shin-carpediem self-assigned this Feb 8, 2023
@shin-carpediem shin-carpediem added the problem Not bug but troublesome issue label Feb 8, 2023
@shin-carpediem shin-carpediem changed the title Reconsider combination of Stateobject and VIPER / StateObjectとVIPERの相性の再検討 Reconsider combination of Stateobject(SwiftUI) and VIPER / StateObject(SwiftUI)とVIPERの相性の再検討 Feb 9, 2023
@shin-carpediem shin-carpediem changed the title Reconsider combination of Stateobject(SwiftUI) and VIPER / StateObject(SwiftUI)とVIPERの相性の再検討 StateObject(SwiftUI)とVIPERの相性の再検討 Mar 9, 2023
@shin-carpediem
Copy link
Owner Author

shin-carpediem commented Jul 1, 2023

StateObjectは、本質的には、ストアドプロパティに用いるstateのクラス版です。
これはつまり、StateObjectもprivateだということです。
なので、View構造体のから、値を更新することはできません。

仮にStateObjectを用いた場合、View構造体の中で、値を更新することになります。
つまり、状態の更新をView構造体が全て担うことになります。

プロジェクトでのアーキテクチャ設計の考え方にもよりますが、このプロジェクトでは、View構造体がロジックを持つようなことはせず、Prsentation層が持つようにし、ObservedObjectの値の更新を通して、View構造体が自動で再描画をするような、MVVMの形を取る(実際には、その拡張としてのVIPERの形になっています)ようにしています。

なので、「ObservedObjectよりもStateObjectの方が良い」というのは、アーキテクチャに寄るとしか言えません。

このプロジェクトでは、ObservedObjectを今後も用いるようにします。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
problem Not bug but troublesome issue
Projects
None yet
Development

No branches or pull requests

1 participant