DEV Community

Cover image for Patterns and Folder Structure for iOS Development
Steven J. Selcuk
Steven J. Selcuk

Posted on

Patterns and Folder Structure for iOS Development

Every two years, a design pattern becomes famous. VIPER was the golden boy before. I mean, it was the top %1 popular question for the whiteboarding stage. So what? It was MVC in UIKit times. Now it's MVVM for modern Swift6/SwiftUI/iOS development

Let's talk

It's just naming and putting files in the correct place. Do not get confused with all the mumbo-jumbo and CS666 something. All these patterns only affect your workflow. Not your code. Views are the same views in SwiftUI, nothing new or changed.

Create Domain/Feature-Based Modules

If you know REACT this is what we have been using for decades. Create containers in a name, e.g., Dashboard display, and do stuff here. It can be Login, About, Services, Landing Page, and Onboarding. One Job -> One domain, so you can isolate them from each other

Do not do business logic in Views

The second rule is not put functions except UI related stuff in views. Do it on ViewModel. Same thing again. Separation & isolation.

Use a Common/Shared folder

This is kinda conflicts with a rule, much more important than all this folder thing. DO NOT REPEAT YOURSELF! So create a common/shared folder for reusable components (like in React), views, etc. Use them.

Reality check: Design Patterns and Architecture Designing are Different Things

MVVM is not a superhero. Yea most of the companies/startup and their teams lives with an idea and are ready to fight. But hey, it's just a decision of naming / foldering, that's it. Not System Architecture. Do not confuse. I mean. If you don't have a solid foundation, eventually your view models inflate and explode, or you have to deal with a race condition for 4 hours, and MVVM can't save you from this. Do not get hyped with random letters shows up in your LinkedIn feed.

Final Conclusion

Every two years, fully refactor your code. Maybe ten years ago, it was five. One simple thing you need to keep in mind if you're starting a project, except if you're a newcomer to an existing storyboard-used VIPER project, it's a different story. Good luck with that. How can I make it easy to rewrite/refactor the whole app 2 years later? Question is: How maintainable? How long does it take? If you have an answer for it. Choose whatever you want for "pattern."

Top comments (0)