17.2 C
Canberra
Monday, October 27, 2025

Conventions for Xcode – The.Swift.Dev.


Learn to set up your codebase. If you’re battling Xcode venture construction, information, naming conventions, learn this.

Apple has a lot frameworks and APIs that I don’t even know a lot of them. We’re additionally dwelling within the age of utility extensions. If you’re making an attempt to create a model new goal in Xcode, you may find yourself scratching your head. 🤔

Conventions for Xcode – The.Swift.Dev.

That is nice for each for builders and end-users, however after creating just a few targets and platforms (your venture grows and) you may ask the query:

How ought to I organise my codebase?

Don’t fear an excessive amount of about it, I may need the correct reply for you! 😉

The issue with advanced initiatives

You may create apps in Xcode for all the key working methods: iOS, macOS, tvOS, watchOS. Within the newest model of Xcode it’s also possible to add greater than 20 extension only for iOS, plus there are many app extensions accessible for macOS as properly. Think about a fancy utility with a number of extensions & targets. This case can result in inconsistent bundle identifiers and extra ad-hoc naming options. Oh, by the way in which watchOS purposes are only a particular extensions for iOS targets and don’t overlook about your assessments, these are particular person targets as properly! ⚠️

So far as I can see, in case you are making an attempt to help a number of platforms you’re going to have quite a lot of targets inside your Xcode venture, moreover each new goal will comprise some sort of supply information and belongings. Ought to I point out schemes too? 😂

Even Apple eliminated it’s Lister pattern code, that demonstrated one in every of a hellish Xcode venture with 14 targets, 11 schemes, however the total venture contained solely 71 Swift supply information. That’s not an excessive amount of code, however you’ll be able to see the problem right here, proper?

It’s time to learn to organise your venture! 💡

Xcode venture group

So my primary thought is to have an inexpensive naming conceptand folder construction contained in the venture. This entails targets, schemes, bundle identifiers, location of supply information and belongings on the disk. Let’s begin with a easy instance that comprises a number of targets to have a greater understanding. 🤓

NOTE: If you’re utilizing the Swift Bundle Supervisor eg. for Swift backends, SPM will generate your Xcode venture information for you, so that you shoudn’t care an excessive amount of about conventions and namings in any respect. 🤷‍♂️

Challenge identify

Are you creating a brand new utility? Be at liberty to call your venture as you need. 😉

Are you going to make a framework? Lengthen your venture identify with the Equipment suffix. Folks normally want to make use of the ProjectKit type for libraries in order that’s the proper solution to go. When you have a killer identify, use that as an alternative of the equipment type! 😛

Accessible platforms

At all times use the next platform names:

Goal naming conference

Identify your targets like:

[platform] [template name]

Don’t embody venture identify within the targets (that might be only a duplicate)
Use the extension names from the brand new goal window (eg. In the present day Extension)
Use “Utility” template identify for the primary utility targets
Use “Framework” as template identify for framework targets
Order your targets in a logical approach (see the instance)

Scheme names

Merely use goal names for schemes too (prefix with venture identify if required).

[project] - [platform] [template name]

You may prefix schemes together with your venture identify if you would like, however the generic rule is right here to make use of the very same identify as your goal. I additionally prefer to separate framework schemes visually from the schems that comprise utility logic, that’s why I all the time transfer them to the highest of the listing. Nevertheless a greater strategy is to separate frameworks right into a standalone git repository & join them by means of a bundle supervisor. 📦

Bundle identifiers

This one is tough due to code signing. You may go along with one thing like this:

[reverse domain].[project].[platform].[template name]

Listed here are the principles:

  • Begin together with your reverse area identify (com.instance)
  • After the area, insert your venture identify
  • Embrace platform names, aside from iOS, I don’t append that one.
  • Use the template identify as a suffix (like .todayextension)
  • Don’t add utility as a template identify
  • Use .watchkitapp, .watchkitextension for legacy watchOS targets
  • Don’t use greater than 4 dots (see instance under)!

NOTE: If you’re going to use com.instance.venture.ios.as we speak.extension that’s not going to work, as a result of it comprises greater than 4 dots. So it is best to merely go along with com.instance.venture.ios.todayextension and names like that. 😢

Anyway, simply all the time attempt to signal your app and undergo the shop. Good luck. 🍀

Challenge folders

The factor is that I all the time create bodily folders on the disk. When you make a bunch in Xcode, properly by default that’s not going to be an precise folder and all of your supply information and belongings might be positioned underneath the venture’s most important listing.

I do know it’s a private desire however I don’t prefer to name an enormous “wasteland” of information as a venture. I’ve seen many chaotic initiatives 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 all the things else (photographs, and so forth).

Below the Sources I all the time make extra subfolders for particular person VIPER modules, or just for controllers, fashions, objects, and so forth.

Instance use case

Here’s a fast instance venture in Xcode that makes use of my conventions.

Xcode naming conventions

As you’ll be able to see I adopted the sample from above. Let’s assume that my venture identify is TheSwiftDev. Here’s a fast overview of the complete setup:

Goal & scheme names (with bundle identifiers):

  • iOS Utility (com.tiborbodecs.theswiftdev)
  • iOS Utility Unit Exams (n/a)
  • iOS Utility UI Exams (n/a)
  • iOS In the present day Extension (com.tiborbodecs.theswiftdev.todayextension)
  • watchOS Utility (com.tiborbodecs.theswiftdev.watchos)
  • watchOS Utility Extension (com.tiborbodecs.theswiftdev.watchos.extension)
  • tvOS Utility (com.tiborbodecs.theswiftdev.macos)
  • macOS Utility (com.tiborbodecs.theswiftdev.tvos)

NOTE: When 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 methodology may seems to be like an overkill at first sight, however belief me it’s price to observe these conventions. As your app grows, ultimately you’ll face the identical points as I discussed to start with. It’s higher to have a plan for the long run.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

[td_block_social_counter facebook="tagdiv" twitter="tagdivofficial" youtube="tagdiv" style="style8 td-social-boxed td-social-font-icons" tdc_css="eyJhbGwiOnsibWFyZ2luLWJvdHRvbSI6IjM4IiwiZGlzcGxheSI6IiJ9LCJwb3J0cmFpdCI6eyJtYXJnaW4tYm90dG9tIjoiMzAiLCJkaXNwbGF5IjoiIn0sInBvcnRyYWl0X21heF93aWR0aCI6MTAxOCwicG9ydHJhaXRfbWluX3dpZHRoIjo3Njh9" custom_title="Stay Connected" block_template_id="td_block_template_8" f_header_font_family="712" f_header_font_transform="uppercase" f_header_font_weight="500" f_header_font_size="17" border_color="#dd3333"]
- Advertisement -spot_img

Latest Articles