What is the difference between Tuist init and scaffold
Table of Contents
Part 4 in the series "Tuist templates and how to use them". In the final part, I want to wrap up everything by telling you my guideline on the difference between init and scaffold command, which I have a hard time figuring out when I have first known Tuist.
Template
The template is a manifest file which use to generate files. It can be static and dynamic. Both init and scaffold commands use a template to bootstrap projects and modules. The template doesn't know which command is going to call it, so it has no such thing as a template for init or a template for scaffold.
You can easily support sarunw.com by checking out this sponsor.
Debug 10x faster with Proxyman: Your ultimate tool to capture HTTPs requests/ responses, natively built for your iPhone and macOS. Special deal for Black Friday: Get 30% off for all Proxyman licenses with code “BLACKFRIDAY2024”.
What is the difference between init and scaffold
The only difference between the two is the purpose of using template files.
- Init command use a template to bootstrap a project from the ground.
- Scaffold uses a template for adding new features or components on existing projects.
Technically both commands can use the same template, but just because you can doesn't mean you should. You should respect the tool and be a good Tuist citizen.
How should we craft a template for init and scaffold
Since we can use init and scaffold commands interchangeably, the only difference lies in the templates. So, the real question is how we should create a template for them. As I mentioned before, Tuist doesn't have any restrictions, but I think there are conventions that we should follow.
Should a template generate Project.swift
Init: Yes, since we use the init command to bootstrap a new project and Project.swift is a core of Tuist, your template should generate that file for users. So users can run tuist generate
and begin the development right away.
Scaffold: No, the scaffold is for an ongoing project. That's means we should already have Project.swift already.
Should a template generate Tuist components
Init: Yes, if you have any helpers or config that you want to use, it is a good idea to generate it all together at the start.
Scaffold: No, the scaffold is mean to spawn new application components, not the project components. Generate Tuist-related components doesn't fit here. If you want to create helpers for your scaffold, you should create it manually or embed it in the init template.
Should a template generate project components
Init: Yes, you might want to create boilerplate files on a new project, e.g., .gitignore
and README.md
. This is what you can put in the init template.
Scaffold: No, we should have that files in place already.
Should a template generate source files
Init: Yes, the template should create main app files.
Scaffold: Yes, the template should create files for new components and features.
What attributes should a template have
Init: There is not enforced by the command, but I suggest you consider having name
and platform
so it aligns with the official template.
Scaffold: No restriction.
You can easily support sarunw.com by checking out this sponsor.
Debug 10x faster with Proxyman: Your ultimate tool to capture HTTPs requests/ responses, natively built for your iPhone and macOS. Special deal for Black Friday: Get 30% off for all Proxyman licenses with code “BLACKFRIDAY2024”.
Conclusion
There are no real guidelines here, and these rules are just from my observation. I hope it can help you get started with Tuist and remove some confusion between these two commands.
Read more article about Tuist, Template, Scaffold, Xcode, Development, or see all available topic
Enjoy the read?
If you enjoy this article, you can subscribe to the weekly newsletter.
Every Friday, you'll get a quick recap of all articles and tips posted on this site. No strings attached. Unsubscribe anytime.
Feel free to follow me on Twitter and ask your questions related to this post. Thanks for reading and see you next time.
If you enjoy my writing, please check out my Patreon https://www.patreon.com/sarunw and become my supporter. Sharing the article is also greatly appreciated.
Become a patron Buy me a coffee Tweet ShareHow to resize a SwiftUI Image and keep its aspect ratio
Learn how to use aspect fit and aspect fill content mode to fit your image to its bounds.
How to initialize @StateObject with parameters in SwiftUI
@StateObject is an essential property wrapper in SwiftUI, but I found the way to initialize them is not obvious.