Contents

darrarski/sort-swift-imports

Sort import statements in your Swift source code.

πŸ› Swift Library

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

.package(
  url: "https://github.com/darrarski/sort-swift-imports.git",
  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

<a href="https://apps.apple.com/app/sort-imports/id1601715398"> <img src="Misc/Download_on_the_App_Store_badge.png" alt="Download on the App Store" align="right" width="200"/> </a>

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 Imports extension in System Preferences β†’ Extensions β†’ Xcode Source Editor.

|macOS| |:-:| |[macOS app screenshot light mode][macOS app screenshot dark mode]|

πŸ…°οΈ iOS application

<a href="https://apps.apple.com/app/sort-imports/id1601715398"> <img src="Misc/Download_on_the_App_Store_badge.png" alt="Download on the App Store" align="right" width="200"/> </a>

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 mode][iPhone app screenshot dark mode]|[iPad app screenshot light mode][iPad app screenshot dark mode]|

πŸ›  Development

Open SortSwiftImports.xcworkspace in Xcode (β©Ύ15.4) 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)
     β”œβ”€ SortSwiftImportsApp (iOS and macOS Application)
     └─ SortSwiftImportsXcodeExtension (Xcode Source Editor Extension)

▢️ Build schemes

  • Use SortSwiftImportsApp scheme to build, run, and test the application on iOS and macOS.
  • 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 individual feature-libraries in isolation.

πŸ™‹β€β™‚οΈ 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?

<a href="https://www.buymeacoffee.com/darrarski" target="_blank"> <img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" align="right" height="60"/> </a>

Consider supporting further development and buy me a coffee.

&nbsp;

πŸ“„ License

Copyright Β© 2021 Dariusz Rybicki Darrarski

License: MIT

Package Metadata

Repository: darrarski/sort-swift-imports

Stars: 11

Forks: 1

Open issues: 0

Default branch: main

Primary language: swift

License: MIT

Topics: sorting, swift, xcode

README: README.md