Sort Swift Imports
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
  
  
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 | 
|---|
![]() ![]()  |  
  
   π
°οΈ 
   iOS application
  
  
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 | 
|---|---|
![]() ![]()  |  
   ![]() ![]()  |  
  
   π  
   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 
SortSwiftImportsMacAppscheme to build and run the macOS application. - Use 
SortSwiftImportsMacAppscheme to run all tests on macOS. - Use 
SortSwiftImportsIOSAppscheme to build and run the iOS application. - Use 
SortSwiftImportsIOSAppscheme to run all tests on iOS simulator. - Use 
SortSwiftImportsXcodeExtensionscheme to build and run the Xcode Source Editor Extension. - Use 
AppIconscheme for building & previewing the app icon in Xcode (use macOS destination). - Use 
ExportAppIconscheme 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?
  
  
Consider supporting further development and buy me a coffee.
   π 
   License
 
Copyright Β© 2021 Dariusz Rybicki Darrarski
License: MIT





