Recorded – watch the full episode on YouTube.
You want code that is beautiful, but also maintainable and scalable and reusable and flexible. What advice do you give to folks to help them split up their large SwiftUI views into smaller, easier to understand more reusable views?
Meng To: Well, perhaps I'm not the best person to answer this question, but I'm going to try to answer from a designer perspective who codes. First of all, in the design tool, more and more designers are using components, are using design systems.
So the way that I look at it is to borrow the same strategy to make sure that every single piece of code is reusable and is three steps customizable. Again, from that principle of the number three, which is something that I've learned a lot from Steve Jobs back in terms of like the way he thinks. The three steps is to make sure that you're not necessarily making a component that can transform itself to be an app or can transform in seven to 10 types of buttons.
“Keep it short, make it reusable, connect it to the design system and try to be consistent between the design and the SwiftUI with UI.”
But if a single button can transform into two types of button or three types of button, that's amazing. You don't want to have like maybe 20 props. When I say props, variables. You might want to have three or five or something like that. Keep it short, make it reusable, connect it to the design system and try to be consistent between the design and the SwiftUI with UI.
So for example, a lot of the naming conventions that I try to do in my team, because a lot of our developers are not native English speakers. So, they have trouble with naming their component. They have trouble naming their views and they make typos. And so, what I try to do in the design is to sort of say, okay, this is a list view, or this is a row.
So, I put that in the design tool when I name the layers. And then when I ship it to developers, they look at it and they're like, “I’m going to use exactly this name.” So, we try to be consistent and during meetings then when we talk to each other, we can say, “okay, remember the row view.” Then it's consistent across the two and it helps with communication as well. So, that's kind of how I look at it.
Paul Hudson: Yeah. Consistency is key in so many things in our job.
This transcript was recorded as part of Swiftly Speaking. You can watch the full original episode on YouTube, or subscribe to the audio version on Apple Podcasts.
SPONSORED ViRE offers discoverable way of working with regex. It provides really readable regex experience, code complete & cheat sheet, unit tests, powerful replace system, step-by-step search & replace, regex visual scheme, regex history & playground. ViRE is available on Mac & iPad.
Link copied to your pasteboard.