Extension management for Swift projects

Extension management for Swift projects

The way that extensions are handled in Swift is lovely. If they exist in any file, they are available project-wide. Meaning you don’t need to import them into a Swift file for functional inclusion. This is great! But if you’re working on a medium to large Swift project, you may need to tweak or add functionality to an extension or two over time.

Find In Project and other avenues of searching are available within the Xcode IDE. That introduces some cognitive load and possibly causing you to lose a thought while you’re doing some menial tasks finding code.

A solution.

You can make an Extensions.swift file in your project and keep all your extensions in it. Import what you need at the top of it – usually UIKit should suffice. You could use //MARK: – UIView – type browse tags in your code to break things into categories too if you needed to.

Pretty handy!

An example to get started.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.