Apple has a lot frameworks and APIs that I do not even know a lot of them. We’re additionally residing within the age of utility extensions. In case you are attempting to create a model new goal in Xcode, you would possibly find yourself scratching your head. 🤔
That is nice for each for builders and end-users, however after creating a couple of targets and platforms (your challenge grows and) you would possibly ask the query:
How ought to I organise my codebase?
Don’t fret an excessive amount of about it, I might need the precise reply for you! 😉
The issue with advanced tasks
You possibly can create apps in Xcode for all the most important working methods: iOS, macOS, tvOS, watchOS. Within the newest model of Xcode you may also add greater than 20 extension only for iOS, plus there are many app extensions obtainable for macOS as nicely. Think about a posh utility with a number of extensions & targets. This case can result in inconsistent bundle identifiers and extra ad-hoc naming options. Oh, by the best way watchOS purposes are only a particular extensions for iOS targets and do not forget about your exams, these are particular person targets as nicely! ⚠️
So far as I can see, in case you are attempting to assist a number of platforms you’re going to have a variety of targets inside your Xcode challenge, moreover each new goal will include some sort of supply information and belongings. Ought to I point out schemes too? 😂
Even Apple eliminated it is Lister pattern code, that demonstrated one in every of a hellish Xcode challenge with 14 targets, 11 schemes, however the total challenge contained solely 71 Swift supply information. That is not an excessive amount of code, however you possibly can see the difficulty right here, proper?
It is time to discover ways to organise your challenge! 💡
Xcode challenge group
So my primary concept is to have an inexpensive naming conceptand folder construction contained in the challenge. This entails targets, schemes, bundle identifiers, location of supply information and belongings on the disk. Let’s begin with a easy instance that accommodates a number of targets to have a greater understanding. 🤓
In case you are utilizing the Swift Package deal Supervisor eg. for Swift backends, SPM will generate your Xcode challenge information for you, so that you shoudn’t care an excessive amount of about conventions and namings in any respect. 🤷♂️
Mission title
Are you creating a brand new utility? Be at liberty to call your challenge as you need. 😉
Are you going to make a framework? Lengthen your challenge title with the Package suffix. Folks normally desire to make use of the ProjectKit model for libraries in order that’s the proper solution to go. When you have a killer title, use that as a substitute of the equipment model! 😛
Obtainable platforms
At all times use the next platform names:
Goal naming conference
Title your targets like:
[platform] [template name]
Do not embody challenge title within the targets (that may be only a duplicate) Use the extension names from the brand new goal window (eg. Right this moment Extension) Use “Software” template title for the principle utility targets Use “Framework” as template title for framework targets Order your targets in a logical approach (see the instance)
Scheme names
Merely use goal names for schemes too (prefix with challenge title if required).
[project] - [platform] [template name]
You possibly can prefix schemes together with your challenge title if you need, however the generic rule is right here to make use of the very same title as your goal. I additionally prefer to separate framework schemes visually from the schems that include utility logic, that is why I all the time transfer them to the highest of the listing. Nonetheless a greater method is to separate frameworks right into a standalone git repository & join them by a bundle supervisor. 📦
Bundle identifiers
This one is tough due to code signing. You possibly can go along with one thing like this:
[reverse domain].[project].[platform].[template name]
Listed below are the foundations:
- Begin together with your reverse area title (com.instance)
- After the area, insert your challenge title
- Embrace platform names, apart from iOS, I do not append that one.
- Use the template title as a suffix (like .todayextension)
- Do not add utility as a template title
- Use .watchkitapp, .watchkitextension for legacy watchOS targets
- Do not use greater than 4 dots (see instance beneath)!
If you’re going to use com.instance.challenge.ios.at present.extension
that is not going to work, as a result of it accommodates greater than 4 dots. So you must merely go along with com.instance.challenge.ios.todayextension
and names like that. 😢
Anyway, simply all the time attempt to signal your app and undergo the shop. Good luck. 🍀
Mission folders
The factor is that I all the time create bodily folders on the disk. In the event you make a bunch in Xcode, nicely by default that is not going to be an precise folder and all of your supply information and belongings will probably be situated below the challenge’s primary listing.
I do know it is a private choice however I do not prefer to name a large “wasteland” of information as a challenge. I’ve seen many chaotic tasks with out correct file group. 🤐
It doesn’t matter what, however I all the time observe this primary sample:
- Create folders for the targets
- Create a Sources folder for the Swift supply information
- Create an Belongings folder for every thing else (photos, and so on).
Underneath the Sources I all the time make extra subfolders for particular person VIPER modules, or just for controllers, fashions, objects, and so on.
Instance use case
Here’s a fast instance challenge in Xcode that makes use of my conventions.
As you possibly can see I adopted the sample from above. Let’s assume that my challenge title is TheSwiftDev. Here’s a fast overview of the total setup:
Goal & scheme names (with bundle identifiers):
- iOS Software (com.tiborbodecs.theswiftdev)
- iOS Software Unit Exams (n/a)
- iOS Software UI Exams (n/a)
- iOS Right this moment Extension (com.tiborbodecs.theswiftdev.todayextension)
- watchOS Software (com.tiborbodecs.theswiftdev.watchos)
- watchOS Software Extension (com.tiborbodecs.theswiftdev.watchos.extension)
- tvOS Software (com.tiborbodecs.theswiftdev.macos)
- macOS Software (com.tiborbodecs.theswiftdev.tvos)
In the event you rename your iOS goal with a WatchKit companion app, watch out!!! You even have to vary the WKCompanionAppBundleIdentifier
property inside your watch utility goal’s Information.plist
file by hand. ⚠️
This technique would possibly seems like an overkill at first sight, however belief me it is value to observe these conventions. As your app grows, ultimately you’ll face the identical points as I discussed to start with. It is higher to have a plan for the long run.