r/iOSProgramming • u/ozzmadman • Nov 26 '23
Discussion Clean Swift and SwiftUI
Hey ๐
I made this post describing my latest thoughts on my journey to combine Clean Swift and SwiftUI, which appear to be incompatible technologies.
If I need to repeat the post here and not just share the link, let me know.
I would like your thoughts and feedback on the above as well as any better idea to combine Clean Swift with SwiftUI.
Thanks in advance ๐
1
Upvotes
2
u/beclops Swift Nov 27 '23
Everybody in here bashing โdogmaticโ views while spitting dogmatic views themselves. Hate to see it. Good post OP
8
u/sisoje_bre Nov 26 '23 edited Nov 26 '23
Wow dude just stop that, seriously, SwiftUI was not meant to be abused like that. "Clean" is just a dogma made up half a century ago by a snake-oil salesman to sell his books. Its not science!
First thing to understand is that SwiftUI view is a value type. That did not exist when clean-dogma was written.
Second thing to understand is that SwiftUI view is not a view. You can call it a "virtual view" just like they call it in ELM architecture that SwiftUI is based on. In reality SwiftUI view is ANY value, even Int can conform to the View!
One major implication is that all MV* hybrids are not applicable to SwiftUI it is just stupid to do so.
Third thing to mention is that body IS the business logic. It is there directly in the protocol definition of the View by Apple and they are breaking the clean-dogma by doing so. They are breaking the clean-dogma all the time, just look at property wrappers like AppStorage and Query. You have to use them in Views
If you like to do it the "clean" way then you need to ask Uncle Bob to provide you with a "clean" framework. You should NOT try to move view management logic OUT into an observable class-type object. By doing so you are breaking the View management of SwiftUI. There are better ways...