Learn Courses My Dashboard

Design pattern used in photo editing apps

I’m working on a photo editing app (in Swift), and I want to communicate and send data back, for example from a brightness slider (grandchild controller) to the preview image (grandparent controller)… Currently I’m using protocol/delegate methods to send data back, but the problem as I create more grandchildren controllers the messier the code gets with all the extra protocol methods.

So my question is, what design pattern should I be using instead to have direct communication with the grandparent controller? I’m new to swift so I’m pretty much unfamiliar with any of the patterns used in such apps…

Thank you.

Welcome to the community!

What do you mean grandchild and grandparent controllers???

Some options you can use are protocol/delegate, callbacks, or Notification Center to pass data between view controllers

Like in this picture for example, I’m adding child view controllers in the same parent view controller… so no navigation

Are you absolutely sure that you need to have multiple ViewControllers in the same View?

What is the purpose of Controller A B and C?

A slider, for example, is simply a Control that can be implemented within a ViewController and does not need to be in its own ViewController. If the slider is there to adjust, say, brightness or contrast then that can be activated to appear to allow that adjustment to be made and you could close it by tapping an associated Done button. That could be the approach for any adjustment control as you progressively edit an image.

Well controller B is for example a tabbar for controller C, and others… which i think has to be a child controller to controller A

Hmmm, could you give us the exact controllers you’re using for A, B and C?

That can help us determine an answer whether or not you actually need child controllers

A: Main Viewcontroller which has the live preview image.
B: Tabbar for sliders, filters, etc…
C: Each tab is a separate viewcontroller (adjustments, filters, stickers)

All of which are in the same screen…

Okay your tab view controller is really the first one and the main view controller (one of the tabs) is inside the first.

The other tabs are all separate view controllers but they’re all under the tab view (not technically inside the other tabs)

So you have A, tab bar controller, and B, C D etc are all inside A at the same level, not cascading down.

Depending on what information you’re passing between your different tabs you could create custom objects that contain multiple values and pass those via delegate/protocol OR you could use callbacks.

You could also save things to core data and then call them at other parts so you’re not technically passing data between VCs, but saving and then recalling it

I’m going to try the custom objects idea and see how it goes. Thank you

1 Like