SwiftExtras is a Swift Package containing Extensions and Helpers for Swift which I use on a regular basis, or find useful.
- Swift 5.9+ (Xcode 15+)
- iOS 16+, macOS 13+, tvOS 16+, watchOS 9+
dependencies: [
.package(url: "https://github.com/0xWDG/SwiftExtras.git", branch: "main"),
],
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "SwiftExtras", package: "SwiftExtras"),
]),
]- In Xcode, open your project and navigate to File → Swift Packages → Add Package Dependency...
- Paste the repository URL (
https://github.com/0xWDG/SwiftExtras) and click Next. - Click Finish.
Generate the macOS-rendered DocC assets from the repository root:
swift run SwiftExtrasScreenshotsTo render with UIKit, boot an iOS Simulator, build the generator for the simulator, and run the resulting executable:
xcodebuild build \
-scheme SwiftExtrasScreenshots \
-destination 'generic/platform=iOS Simulator' \
-derivedDataPath .build/SwiftExtrasScreenshots-iOS \
CODE_SIGNING_ALLOWED=NO
xcrun simctl spawn booted \
"$PWD/.build/SwiftExtrasScreenshots-iOS/Build/Products/Debug-iphonesimulator/SwiftExtrasScreenshots"The generator prints its output directory when it finishes. On iOS, screenshots
are saved under Documents/SwiftExtrasScreenshots with an -ios filename suffix
so they can coexist with the desktop assets. Set
SWIFT_EXTRAS_SCREENSHOT_OUTPUT to override the destination with a writable
path.
To capture localized screenshots of an app that uses SwiftExtras, add the
SwiftExtrasScreenshotTesting product to the app's UI-test target and subclass
ScreenshotTestCase. See the screenshot testing guide
for a complete light/dark, multi-language example.
Run the reusable platform test script from the repository root:
Scripts/test-all-platforms.shOn macOS, the script runs the test suite locally, builds the package for every
supported Apple platform whose SDK is installed in the selected Xcode, and
runs the Linux suite using
Apple container. Start the service with
container system start before running the script. Set SKIP_LINUX=1 to omit
the containerized Linux tests, or set SWIFT_CONTAINER_IMAGE to select another
Swift image. Missing Apple platform SDKs are reported as skipped rather than as
build failures. Apple platform builds are also skipped when CI=true; macOS
and Linux tests continue to run in CI. On Linux, the script runs swift test
directly.
The screenshot assets are shared with the DocC catalog and can be refreshed with the command above.
🦋 @0xWDG 🐘 mastodon.social/@0xWDG 🐦 @0xWDG 🧵 @0xWDG 🌐 wesleydegroot.nl 🤖 Discord
Interested learning more about Swift? Check out my blog.


















