In the last couple of months I was trying to add LockScreenCapture feature to my app MultiCam, it wasn't an easy takes at all and finally thank god submitted a new build today with the feature.
Custom Control Widgets icon
From it I learned a lot of things the first one is the fact that we can't use a custom image in the control widgets but if you want to add a custom shape for the control widget you need to create custom SF symbol (which wasn't an easy task for me as an engineer ๐).
Generic Views with Different ViewModels
The second important lesson was how to create a generic view that can work with different viewModel types. Let me explain the problem:
I had the same view in different targets in the app, but they required different viewModels due to slight differences in functionality. The obvious solution would be to create two versions of the view, but this would make maintenance difficult - any change (like adding a new color) would need to be duplicated across both targets.
To overcome this challenge, I wanted to make the View accept a viewModel that conforms to a certain protocol instead of a concrete type. However, this isn't as straightforward as it might seem because the view needs to observe a specific instance of a specific type.
The workaround is to use generics, like so:
By using this approach, the observer can observe a specific instance of a type that conforms to a specific protocol. This enables me to easily share views across different targets while maintaining different functionalities.
Sorry for being late this week โค๏ธ if you have any feedback message me on iMessage: engomarelsayed@icloud.com
Community Articles