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
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?
Consider supporting further development and buy me a coffee.
? License
Copyright © 2021 Dariusz Rybicki Darrarski
License: MIT