|
Hi everyone! As a former PM/Designer, I have no industry coding experience - and I've come to realize that my code organization skills are horrible. I have a SwiftUI view similar to the example below (but far worse), where I have 5-6 if-else statements to validate if certain properties are loaded before presenting the final views. Somebody suggested that I write helper functions to make it more readable, but then with so many environmentObjects to pass and use in each view, I found that passing classes as objects in helper functions makes it just as complex as simply using nested if loops. So in a scenario where you have multiple managers to pass around views (like the example below) what would be the best inudstry-convention to fix the pyramid of doom?
|
|
Lucas confesses:
I will save the jokes for Dilbert! I am sure there are dozens of great panels that address your situation! I would encourage you to put your program managment and designer skills to use! Yes, your code is a mess. So take a step back, and review your GANTT chart. What is your end goal? Designer: The user wants a fluid experience. This is a contrived discussion. But I hope you can see your skills are useful. One of the lessons you may have missed: SwiftUI is a declarative language. You are mixing procedural logic in with your views. Let your designer skills guide how the final views should look. Let your designer tell you what data is needed. Then put your PM to work. Create tasks and subtasks and delegate them to other workers. Don't ask your view (your designer) to do this heavy lifting and decision making. The work of fetching data, organizing data and decision making is best left to a business object. So task the business end of your 'project team' with these tasks. Stop CodingTake an evening and stop coding. List all your use cases. Like a PM, list all the tasks necessary to realize your goals. Then create a basic work breakdown diagram. Just like a work breakdown structure, write up tasks to a very low level. Write down the data they need, the function they perform, and the data they produce. Who is the best person to make decisions on manager or property data? I am guessing it's not your designer. So separate your business tasks from your display tasks. One person fetches the data from the store room. Another person filters the data, only selecting the necessary records. Yet another person is in charge of validating the data, and formatting it in a nice easy way for the designer. The designer take the simplified data, and efficiently applies the desired formatting, colors and paints. You've got this! |
|
I don't know if this helps? Here are a few lines of code. Please note how the Designer and the PM work independently. Don't ask the Designer to put business rules in the views. Don't ask the PM to make design decisions. Keep those roles separate as best you can.
I think your code will be more Swifty if you consider moving your business code OUT of the views. Put your PM skills to work and move the business functions OUT OF the view code. |
|
@Obelix to the rescue again! Thank you for the words of wisdom that I will carry for a long time to come. Although bringing up that I'm an ex-product manager helped me get an answer with great insights, I think it also might have de-focused from what I wanted to ask (apart from my sample code being a little too vague). By "manager" in my sample code, I simply meant a helper class like "LocationManager", not in terms of a role 'manager'! I tried extending this thread, but since the response Obelix gave is a different type of "solution", I will post another question with a more detailed sample code. Thank you! |
SPONSORED Join a FREE crash course for mid/senior iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a complete senior developer! Hurry up because it'll be available only until September 29th.
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.