iOS simple painting App — demonstration in Swift, SwiftUI and RxSwift
Paintings apps are very common stuff in AppStore. I would like introduce one of the most easiest implemantation of this kind application. It’s about free-hand painting without layering. To be more interesting i created same functionality in 3-different ways — pure Swift, more powerfull RxSwift and modern SwiftUI.
It's my first code in SwiftUI, so be tolerant, please :)
Pure Swift solution
The biggest problem, what i see here is a lot work with Storyboard. Sure, you can argue, that i can write it all by code, but then i would write more code and take much time… :)
Next problem is setting frame of imageView, without it doesn’t fit coordinates between displayed image and real image. Same problem is in RxSwift solution too.
Solution via RxSwift and RxGesture is more nice. I don’t have to set UIPanGestureRecognizer in storyboard and whole looks more cool. But it’s not for free, Rx world is hard to understand and takes a while get in at least from a part. From my perspective its good in cooperation with MVVM. Reactive programing can helps a lot in complex tasks and sometimes it can drowns you in its complexity…
This was new for me. I read about it in time when Apple introduced SwiftUI, but until now i had not project, where i can try it.
I don’t have it still by the way :)
Yes, i working with React-native mainly, but iOS i like.
What i appreciated it was that i don't have to dealing with coordinates between canvas and image. It just works and i like it :)
If you are interested in the mysterious function that makes drawing, here it is. It’s not rocket science, but it serves its purpose.
Complete source code is avaliable on:
Thanks for reading!