iOS simple painting App — demonstration in Swift, SwiftUI and RxSwift

Petr Lzicar
3 min readJan 8, 2022
Simple painting App preview
Painting App preview

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.

Pure Swift solution

RxSwift solution

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…

SwiftUI solution

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 :)

I had to search a lot for completing this working solution, but finish looks pretty straitforward. My appreciation give component system, which make code readable and looks that can be reusable. It’s remind me React from javascript world. Declarative style also has something in it, RxSwift use declarative approche too, but SwiftUI move it on next level.

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 :)

Painting function

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:
https://gitlab.com/petrlz-medium/iossimplepaintapp

Thanks for reading!

--

--