Skip to content

SwiftExtension 2.0.0

Latest

Choose a tag to compare

@ANSCoder ANSCoder released this 27 Oct 17:50
a0e93b8

Highlights

  • Swift Package Manager. Add the package by URL. Drag-and-drop copying still works, but the package is the supported path.
  • Swift 6 language mode with strict concurrency checking. No @unchecked Sendable, nonisolated(unsafe), or @preconcurrency.
  • Public, documented API. Every public declaration has a DocC comment with a usage example. Build the docs with Product → Build Documentation in Xcode.
  • New SwiftUI helpers: shake(trigger:), shimmer(_:), redactedShimmer(_:), snapshot(scale:), roundedBorder(_:width:cornerRadius:), and Color(hex:).
  • New Foundation helpers: chunked(into:), removingDuplicates(on:), clamped(to:), rounded(toPlaces:), orEmpty, asDictionary(), isValidURL, initials, truncated(to:), URL query helpers, Bundle.appVersion and buildNumber, and calendar helpers on Date.
  • New UIKit helpers: UIColor.hexString, UIView.addSubviews(_:), and UIView.pinToEdges(of:insets:), which follows right-to-left layout.
  • Catalog app with 56 live examples. Each one has a Play button and copyable code.

Requirements

Swift 6.0+ (Swift 6 language mode)
iOS 17.0+
macOS 14.0+ (Foundation helpers only)
Dependencies None

Previous versions supported older iOS releases. 2.0.0 drops them.

Breaking changes

  • Minimum platforms and language mode. iOS 17 and Swift 6 are now required.
  • changeDate(_:) returns String?. It used to force-unwrap and crash on bad input.
  • UIImage.toBase64String is String?. It returns nil if the image can't be encoded as PNG.
  • ExFunction is an enum. Its static methods are unchanged.
  • dismissKeyboardOnTap() is unavailable in app extensions. It uses UIApplication.
  • UINavigationBar helpers use UINavigationBarAppearance. The default title color is now .label, so it adapts to dark mode.
  • String.isEmail accepts top-level domains up to 64 characters, matching the UIKit text field helper. It used to accept only up to 4.
  • UIColor(hex:) treats invalid input as gray. Before, it could produce unexpected colors. It now also accepts # and 8-digit alpha.
  • showAlertWithMessage takes a duration (default three seconds). The completion handler now runs on the main actor.

Upgrading

// changeDate now returns an optional
if let formatted = "".changeDate("2026/1/05") {
    label.text = formatted   // "January 05, 2026"
}

// toBase64String is optional
let encoded: String? = image.toBase64String

// dismissKeyboardOnTap: keep it out of app extension targets
#if !APPLICATION_EXTENSION
view.dismissKeyboardOnTap()
#endif

Deprecated, still working, and will be removed in a future major release:

  • showAleartViewwithTitle(_:message:) → showAlertView(title:message:)
  • setCornerRadious() → setCornerRadius()

Behavior changes

  • Date.toString() and toTimeString() use value-based format styles. The output format is the same, but they no longer share a DateFormatter.
  • showAlertWithMessage waits with a main-actor Task. It no longer uses a dispatch timer, so it is cancelled with its owner.
  • UIImage.halfSizeImage and quarterhalfSizeImage render at the screen's scale, so the output is sharper on Retina displays.
  • scrollToBottom and scrollToTop respect adjustedContentInset, including the safe area.
  • getRawJSON(from:) no longer drops non-ASCII characters.

Fixes

  • UIColor(hex:) accepts # and validates each character.
  • getRawJSON(from:) handles non-ASCII text.
  • Force unwraps that could crash were removed from the library.
  • UILabel.attribute(_:effect:) no longer crashes when a label has no font.

Known limitations

  • UILabel.attribute(_:effect:) fixes font sizes when it runs. Call it again after a Dynamic Type change.
  • showAlertWithMessage hides its message after the duration, which some users may miss. Use showAlertView(title:message:) for messages users must read.

Full changelog

See [CHANGELOG.md](https://github.com/ANSCoder/Swift-Extension/blob/main/CHANGELOG.md).