Sort import statements in your Swift source code

Overview

Sort Swift Imports

Swift 5.5 platform macOS iOS

Sort import statements in your Swift source code.

πŸ› Swift Library

Add sort-swift-imports package dependency to your Swift Package:

.package(
  name: "sort-swift-imports",
  url: "https://github.com/darrarski/sort-swift-imports.git",
  .upToNextMajor(from: "1.0.0")
),

Add SortSwiftImports library as a dependency to your targets:

.product(
  name: "SortSwiftImports", 
  package: "sort-swift-imports"
),

Use SortSwiftImports from your code:

import SortSwiftImports

let sortSwiftImports: SortSwiftImports = .live
let code: String = // swift source code
let result = sortSwiftImports(in: code)
switch result {
case let .success(output):
  print(output)
case let .failure(error):
  print(error)
}

πŸ…°οΈ macOS application

Download on the App Store

Native SwiftUI macOS application that you can use to sort imports in your Swift source code. Just paste your code and click the Sort Swift Imports button.

It also contains Xcode Source Editor extensionso that you can sort your Swift imports directly from Xcode. Ensure you have enabled Sort Swift Imports Extension in System Preferences β†’ Extensions β†’ Xcode Source Editor.

macOS
macOS app screenshot light modemacOS app screenshot dark mode

πŸ…°οΈ iOS application

Download on the App Store

Native SwiftUI iOS application that you can use to sort imports in your Swift source code. Just paste your code and tap βš™οΈ β†’ Sort Swift Imports.

On your iPad, you can use multiple windows of the app simultaneously.

iPhone iPad
iPhone app screenshot light modeiPhone app screenshot dark mode iPad app screenshot light modeiPad app screenshot dark mode

πŸ›  Development

Open SortSwiftImports.xcworkspace in Xcode (β©Ύ13.2) for development.

🧰 Workspace structure

SortSwiftImports (Xcode Workspace)
 β”œβ”€ sort-swift-imports (Swift Package)
 |   └─ SortSwiftImports (Library)
 β”œβ”€ sort-swift-imports-app (Swift Package)
 |   β”œβ”€ AppFeature (Library)
 |   └─ EditorFeature (Library)
 β”œβ”€ sort-swift-imports-app-icon (Swift Package)
 |   β”œβ”€ AppIcon (Library)
 |   └─ AppIconExport (macOS executable)
 └─ Project (Xcode Project)
     β”œβ”€ SortSwiftImportsMacApp (macOS Application)
     β”œβ”€ SortSwiftImportsIOSApp (iOS Application)
     └─ SortSwiftImportsXcodeExtension (Xcode Source Editor Extension)

▢️ Build schemes

  • Use SortSwiftImportsMacApp scheme to build and run the macOS application.
  • Use SortSwiftImportsMacApp scheme to run all tests on macOS.
  • Use SortSwiftImportsIOSApp scheme to build and run the iOS application.
  • Use SortSwiftImportsIOSApp scheme to run all tests on iOS simulator.
  • Use SortSwiftImportsXcodeExtension scheme to build and run the Xcode Source Editor Extension.
  • Use AppIcon scheme for building & previewing the app icon in Xcode (use macOS destination).
  • Use ExportAppIcon scheme for exporting the app icon into asset catalog (use macOS destination).

Use other schemes for building and testing the libraries.

πŸ™‹β€β™‚οΈ Contributing

  • All contributions are welcome!
  • Create a pull request containing your changes or bug fixes.
  • Make sure to add tests for the new/updated code.

β˜•οΈ Do you like the project?

Buy Me A Coffee

Consider supporting further development and buy me a coffee.

 

πŸ“„ License

Copyright Β© 2021 Dariusz Rybicki Darrarski

License: MIT

You might also like...
The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/watchOS/macOS/Linux).

Analytics-Swift The hassle-free way to add Segment analytics to your Swift app (iOS/tvOS/watchOS/macOS/Linux/iPadOS). Analytics helps you measure your

Easy direct access to your database 🎯

OHMySQL β˜…β˜… Every star is appreciated! β˜…β˜… The library supports Objective-C and Swift, iOS and macOS. You can connect to your remote MySQL database usin

Your Data Storage Troubleshooter πŸ› 
Your Data Storage Troubleshooter πŸ› 

Your Data Storage Troubleshooter πŸ›  Introduction StorageKit is a framework which reduces the complexity of managing a persistent layer. You can easily

A Generic CoreData Manager to accept any type of objects. Fastest way for adding a Database to your project.
A Generic CoreData Manager to accept any type of objects. Fastest way for adding a Database to your project.

QuickDB FileManager + CoreData ❗️ Save and Retrieve any thing in JUST ONE line of code ❗️ Fast usage dataBase to avoid struggling with dataBase comple

Stuff application – keep track of your stuff.

stuff-app Stuff application – keep track of your stuff. Platforms App to be released for iOS 15, iPadOS 15 and macOS 12 Monterey. Purpose Project is d

Stuff application – keep track of your stuff

stuff-app Stuff application – keep track of your stuff. Platforms App to be released for iOS 15, iPadOS 15 and macOS 12 Monterey. Purpose Project is d

A CLI tool for the survey of the SSH-Key strength in your GitHub organization members.

GitHub organization SSH-keys checker A CLI tool for the survey of the SSH-Key strength in your GitHub organization members. Requirements macOS 12.0+ S

Check your emails before someone else does

Checkpoint Proofread your emails before your mom does 🧠 Have you ever meant to

Innova CatchKennyGame - The Image Tap Fun Game with keep your scores using Core Database
Innova CatchKennyGame - The Image Tap Fun Game with keep your scores using Core Database

Innova_CatchKennyGame The Image Tap Fun Game with keep your scores using Core Da

Releases(v1.0.0)
Owner
Dariusz Rybicki
Software Engineer, iOS & Mac Developer, Scrum Master
Dariusz Rybicki
Classes-and-structures-in-swift - This source files show what is the difference between class and structure

This source files show what is the difference between class and structure You ca

null 0 Jan 4, 2022
This project has been developed to understand GraphQL and Diffable Data Source. Created on 20.06.2022.

SpaceX Launches First in first. You need to build all packages before building the project. Packages: Extensions API Open Extensions folder under proj

Okan YΓΌcel 3 Sep 29, 2022
PJAlertView - This library is to make your own custom alert views to match your apps look and feel

PJAlertView - This library is to make your own custom alert views to match your apps look and feel

prajeet 6 Nov 10, 2017
Check your Valorant store from your phone!

Valorant Store Checker Description VSC (Valorant Store Tracker) is an open source iOS app that allows you to track your store and preview your skins.

Gordon 20 Dec 29, 2022
Store and retrieve Codable objects to various persistence layers, in a couple lines of code!

tl;dr You love Swift's Codable protocol and use it everywhere, who doesn't! Here is an easy and very light way to store and retrieve Codable objects t

null 149 Dec 15, 2022
Enables developers to write code that interacts with CloudKit in targets that don't support the CloudKit Framework directly

CloudKit Web Services This package enables developers to write code that interac

Eric Dorphy 3 May 11, 2022
Enables developers to write code that interacts with CloudKit in targets that don't support the CloudKit Framework directly

CloudKit Web Services This package enables developers to write code that interac

Eric Dorphy 2 Dec 27, 2021
βš™οΈΒ A tiny property wrapper for UserDefaults. Only 60 lines of code.

βš™οΈ A tiny property wrapper for UserDefaults. Only 60 lines of code. import Persistent extension UserDefaults { // Optional property @Per

Mezhevikin Alexey 6 Sep 28, 2022
Typed key-value storage solution to store Codable types in various persistence layers with few lines of code!

?? Stores A typed key-value storage solution to store Codable types in various persistence layers like User Defaults, File System, Core Data, Keychain

Omar Albeik 94 Dec 31, 2022
ObjectBox Swift - persisting your Swift objects superfast and simple

ObjectBox Swift ObjectBox is a superfast, light-weight object persistence framework. This Swift API seamlessly persists objects on-device for iOS and

ObjectBox 380 Dec 19, 2022