Contents

0xwdg/swiftextras

SwiftExtras is a Swift Package containing Extensions and Helpers for Swift which I use on a regular basis, or find useful.

Requirements

  • Swift 5.9+ (Xcode 15+)
  • iOS 16+, macOS 13+, tvOS 16+, watchOS 9+

Installation (Pakage.swift)

dependencies: [
    .package(url: "https://github.com/0xWDG/SwiftExtras.git", branch: "main"),
],
targets: [
    .target(name: "MyTarget", dependencies: [
        .product(name: "SwiftExtras", package: "SwiftExtras"),
    ]),
]

Installation (Xcode)

  1. In Xcode, open your project and navigate to File β†’ Swift Packages β†’ Add Package Dependency...
  2. Paste the repository URL (https://github.com/0xWDG/SwiftExtras) and click Next.
  3. Click Finish.

Update Screenshots

Generate the macOS-rendered DocC assets from the repository root:

swift run SwiftExtrasScreenshots

To 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.

Test All Platforms

Run the reusable platform test script from the repository root:

Scripts/test-all-platforms.sh

On 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.

Custom Views (+ Screenshots)

The screenshot assets are shared with the DocC catalog and can be refreshed with the command above.

| View | iOS Screenshot | | --- | --- | | CardView | [CardView on iOS] | | BorderBeamEffect | [Border beam modifier on iOS] | | CarouselView | [CarouselView on iOS] | | ConfirmationButton | [ConfirmationButton on iOS] | | DisclosureSection | [DisclosureSection on iOS] | | HorizontalStepper | [HorizontalStepper on iOS] | | IndexedList | [IndexedList on iOS] | | LabeledTextField | [LabeledTextField on iOS] | | LimitedTextField | [LimitedTextField on iOS] | | MonthYearPickerView | [MonthYearPickerView on iOS] | | MultiSelectPickerView | [MultiSelectPickerView on iOS] | | MultiSelectView | [MultiSelectView on iOS] | | NotificationView | [NotificationView on iOS] | | SEAcknowledgementView | [SEAcknowledgementView on iOS] | | SEChangeLogView | [SEChangeLogView on iOS] | | SplitActionButton | [SplitActionButton on iOS] | | StickySection | [StickySection on iOS] | | VerificationField | [VerificationField on iOS] | | WStack | [WStack on iOS] |

Contact

πŸ¦‹ @0xWDG 🐘 mastodon.social/@0xWDG 🐦 @0xWDG 🧡 @0xWDG 🌐 wesleydegroot.nl πŸ€– Discord

Interested learning more about Swift? Check out my blog.

Package Metadata

Repository: 0xwdg/swiftextras

Default branch: main

README: README.md