Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darrarski/sort-swift-imports
Sort import statements in your Swift source code.
https://github.com/darrarski/sort-swift-imports
sorting swift xcode
Last synced: about 1 month ago
JSON representation
Sort import statements in your Swift source code.
- Host: GitHub
- URL: https://github.com/darrarski/sort-swift-imports
- Owner: darrarski
- License: mit
- Created: 2021-12-23T01:10:25.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-05-14T16:46:55.000Z (8 months ago)
- Last Synced: 2024-11-30T17:49:17.987Z (about 1 month ago)
- Topics: sorting, swift, xcode
- Language: Swift
- Homepage:
- Size: 13.5 MB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Sort (Swift) Imports
![Swift 5.10](https://img.shields.io/badge/swift-5.10-orange.svg)
![platform macOS iOS](https://img.shields.io/badge/platform-macOS_|_iOS-blue.svg)Sort `import` statements in your Swift source code.
## 🏛 Swift Library
Add `sort-swift-imports` package dependency to your Swift Package:
```swift
.package(
url: "https://github.com/darrarski/sort-swift-imports.git",
from: "1.0.0"
),
```Add `SortSwiftImports` library as a dependency to your targets:
```swift
.product(
name: "SortSwiftImports",
package: "sort-swift-imports"
),
```Use `SortSwiftImports` from your code:
```swift
import SortSwiftImportslet 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 extension**so 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](Misc/Screenshots/macOS/macOS-light-1.png#gh-light-mode-only)![macOS app screenshot dark mode](Misc/Screenshots/macOS/macOS-dark-1.png#gh-dark-mode-only)|## 🅰️ 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|
|:-:|:-:|
|![iPhone app screenshot light mode](Misc/Screenshots/iPhone-5.5in/iPhone-5.5in-light-1.png#gh-light-mode-only)![iPhone app screenshot dark mode](Misc/Screenshots/iPhone-5.5in/iPhone-5.5in-dark-1.png#gh-dark-mode-only)|![iPad app screenshot light mode](Misc/Screenshots/iPad-Pro-12.9in-2nd-gen/iPad-Pro-12.9in-2nd-gen-light-1.png#gh-light-mode-only)![iPad app screenshot dark mode](Misc/Screenshots/iPad-Pro-12.9in-2nd-gen/iPad-Pro-12.9in-2nd-gen-dark-1.png#gh-dark-mode-only)|## 🛠 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?
Consider supporting further development and buy me a coffee.
## 📄 License
Copyright © 2021 Dariusz Rybicki Darrarski
License: [MIT](LICENSE)