A handy collection of more than 500 native Swift extensions to boost your productivity.

Overview

Build Status Platforms Cocoapods Carthage compatible SPM compatible Accio supported codecov docs Swift Xcode MIT Slack Channel

SwifterSwift is a collection of over 500 native Swift extensions, with handy methods, syntactic sugar, and performance improvements for wide range of primitive data types, UIKit and Cocoa classes –over 500 in 1– for iOS, macOS, tvOS, watchOS and Linux.

Whats New in v5.3?

Requirements

  • iOS 10.0+ / tvOS 9.0+ / watchOS 2.0+ / macOS 10.10+ / Ubuntu 14.04+
  • Swift 5.0+

Looking to use SwifterSwift for older versions of Swift

SwifterSwift is Swift v5.0+ compatible starting from v5

  • To use with Swift 3 / Xcode 8.x please ensure you are using v3.1.1.
  • To use with Swift 3.2 / Xcode 9.x please ensure you are using v3.2.0.

Installation

CocoaPods

To integrate SwifterSwift into your Xcode project using CocoaPods, specify it in your Podfile:

- Integrate All extensions (recommended):

pod 'SwifterSwift'

- Integrate SwiftStdlib extensions only:

pod 'SwifterSwift/SwiftStdlib'

- Integrate Foundation extensions only:

pod 'SwifterSwift/Foundation'

- Integrate UIKit extensions only:

pod 'SwifterSwift/UIKit'

- Integrate AppKit extensions only:

pod 'SwifterSwift/AppKit'

- Integrate MapKit extensions only:

pod 'SwifterSwift/MapKit'

- Integrate CoreGraphics extensions only:

pod 'SwifterSwift/CoreGraphics'

- Integrate CoreLocation extensions only:

pod 'SwifterSwift/CoreLocation'

- Integrate SpriteKit extensions only:

pod 'SwifterSwift/SpriteKit'

- Integrate SceneKit extensions only:

pod 'SwifterSwift/SceneKit'

- Integrate StoreKit extensions only:

pod 'SwifterSwift/StoreKit'

- Integrate Dispatch extensions only:

pod 'SwifterSwift/Dispatch'

- Integrate WebKit extensions only:

pod 'SwifterSwift/WebKit'

- Integrate HealthKit extensions only:

pod 'SwifterSwift/HealthKit'
Carthage

To integrate SwifterSwift into your Xcode project using Carthage, specify it in your Cartfile:

github "SwifterSwift/SwifterSwift" ~> 5.3
Swift Package Manager

You can use The Swift Package Manager to install SwifterSwift by adding the proper description to your Package.swift file:

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    targets: [],
    dependencies: [
        .package(url: "https://github.com/SwifterSwift/SwifterSwift.git", from: "5.3.0")
    ]
)

Next, add SwifterSwift to your targets dependencies like so:

.target(
    name: "YOUR_TARGET_NAME",
    dependencies: [
        "SwifterSwift",
    ]
),

Then run swift package update.

Note that the Swift Package Manager doesn't support building for iOS/tvOS/macOS/watchOS apps – see Accio in the next section for that.

Accio

Accio is a dependency manager based on SwiftPM which can build frameworks for iOS/macOS/tvOS/watchOS. Therefore the integration steps are exactly the same as described above. Once your Package.swift file is configured, you need to run accio update instead of swift package update though.

Manually

Add the SwifterSwift folder to your Xcode project to use all extensions, or a specific extension.

For your test targets you can also add the XCTest folder.

List of All Extensions

SwiftStdlib Extensions
Foundation Extensions
UIKit Extensions
AppKit Extensions
CoreGraphics Extensions
CoreLocation Extensions
CoreAnimation Extensions
MapKit Extensions
SpriteKit Extensions
SceneKit Extensions
StoreKit Extensions
Dispatch Extensions
WebKit Extensions
HealthKit Extensions
XCTest Extensions

How cool is this?

SwifterSwift is a library of over 500 properties and methods, designed to extend Swift's functionality and productivity, staying faithful to the original Swift API design guidelines.

Check Examples.playground from the project for some cool examples!

Documentation

Documentation for all extensions, with examples, is available at swifterswift.com/docs

Get involved

We want your feedback. Please refer to contributing guidelines before participating.

Slack Channel: Slack

It is always nice to talk with other people using SwifterSwift and exchange experiences, so come join our Slack channel.

Thanks

Special thanks to:

License

SwifterSwift is released under the MIT license. See LICENSE for more information.

Comments
  • Added zoom extension to MapView

    Added zoom extension to MapView

    I wanted to contribute, but I'm very inexperienced in contributing to open source projects. I'd appreciate it if you could tell me what's missing :)

    Checklist

    • [x] I checked the Contributing Guidelines before creating this request.
    • [x] New extensions are written in Swift 5.0.
    • [x] New extensions support iOS 8.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+, or use @available if not.
    • [x] I have added tests for new extensions, and they passed.
    • [x] All extensions have a clear comments explaining their functionality, all parameters and return type in English.
    • [x] All extensions are declared as public.
    • [x] I have added a changelog entry describing my changes.
    opened by mustafagunes 39
  • shadowOffset for UILabel is conflict with UILabel's property.

    shadowOffset for UILabel is conflict with UILabel's property.

    [v] I've read, understood, and done my best to follow the Contributing guidelines before opening this issue.

    What did you do?

    Set shadowOffset, shadowColor, shadowRadius inspectable value on UILabel.

    What did you expect to happen?

    UILabel with proper shadow

    What happened instead?

    shadowOffset is not applied, because UILabel has shadowOffset property. So shadow is always above text, because layer.shadowOffset default value is (0, -3) (Also UILabel has shadowColor property.)

    SwifterSwift Environment

    • SwifterSwift version: 4.6.0
    • Xcode version: 10
    • macOS version running Xcode: 10.14.2
    • Swift version: 4.2
    • Platform(s) running SwifterSwift: iOS

    Demo Project

    Please link to or upload a project we can download that reproduces the issue.

    confirmed bug: source help wanted good first issue 
    opened by mlight3 23
  • Added new protocol for UIViewController to instantiate it from storyboard

    Added new protocol for UIViewController to instantiate it from storyboard

    Checklist

    • [x] I checked the Contributing Guidelines before creating this request.
    • [x] New extensions are written in Swift 5.0.
    • [x] New extensions support iOS 10.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+, or use @available if not.
    • [x] I have added tests for new extensions, and they passed.
    • [x] All extensions have a clear comments explaining their functionality, all parameters and return type in English.
    • [x] All extensions are declared as public.
    • [x] I have added a changelog entry describing my changes.
    opened by VatoKo 19
  • Add init(light:dark:) to NSColor and UIColor

    Add init(light:dark:) to NSColor and UIColor

    This extension allows to create an NSColor or UIColor with different colors for light mode and dark mode. I created separate NSColorExtensions.swift and UIColorExtensions.swift files, because NSColor and UIColor use different APIs for this problem and can't be unified.

    I couldn't figure out how to create a test for macOS, because it uses NSAppearance instead of UITraitCollection. Any suggestions?

    Checklist

    • [x] I checked the Contributing Guidelines before creating this request.
    • [x] New extensions are written in Swift 5.0.
    • [x] New extensions support iOS 8.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+, or use @available if not.
    • [x] I have added tests for new extensions, and they passed.
    • [x] All extensions have a clear comments explaining their functionality, all parameters and return type in English.
    • [x] All extensions are declared as public.
    • [x] I have added a changelog entry describing my changes.
    opened by MaxHaertwig 18
  • Array.withoutDuplicates(keyPath:)

    Array.withoutDuplicates(keyPath:)

    🚀 Fixed #653. Added withoutDuplicates(keyPath:) to Array.

    Checklist

    • [x] I checked the Contributing Guidelines before creating this request.
    • [x] New extensions are written in Swift 5.0.
    • [x] New extensions support iOS 8.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+, or use @available if not.
    • [x] I have added tests for new extensions, and they passed.
    • [x] All extensions have a clear comments explaining their functionality, all parameters and return type in English.
    • [x] All extensions are declared as public.
    • [x] I have added a changelog entry describing my changes.
    opened by RomanPodymov 18
  • Getting `ambiguous use of 'makeIterator()'` error when building package with Xcode 14

    Getting `ambiguous use of 'makeIterator()'` error when building package with Xcode 14

    Describe the bug The package will fail to build and install when used inside a project being compiled on Xcode 14 beta, with an ambiguous use of 'makeIterator()' error.

    To Reproduce

    1. Add SwifterSwift as a package inside an iOS project.
    2. Open project in Xcode 14 beta.
    3. Attempt to build app.

    Expected behavior The SwifterSwift package will not fail to build when using Xcode 14 beta.

    Additional context

    Here's a screenshot of the error: Screen Shot 2022-08-31 at 10 07 12 AM

    I'm about to open a PR which addresses this issue!

    possible bug 
    opened by ianclawson 17
  • Update UIButton extensions

    Update UIButton extensions

    Sometimes I need the image to be on the right or below the text. So add imageRightText on UIButton

    | type | imageAboveText: false | imageAboveText: true  | | --- | --- | --- | | imageRightText: false| Image/Text |

    Image
    ---- 
    Text
    | | imageRightText: true | Text/Image |
    Text
    ---- 
    Image
    |

    Checklist

    • [x] I checked the Contributing Guidelines before creating this request.
    • [x] New extensions are written in Swift 5.0.
    • [x] New extensions support iOS 10.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+, or use @available if not.
    • [x] I have added tests for new extensions, and they passed.
    • [x] All extensions have a clear comments explaining their functionality, all parameters and return type in English.
    • [x] All extensions are declared as public.
    • [x] I have added a changelog entry describing my changes.
    stale 
    opened by Jayxiang 17
  • Added 'applyGradient' method to UIViewExtensions

    Added 'applyGradient' method to UIViewExtensions

    🚀

    Checklist

    • [x] I checked the Contributing Guidelines before creating this request.
    • [x] New extensions are written in Swift 5.0.
    • [x] New extensions support iOS 8.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+, or use @available if not.
    • [x] I have added tests for new extensions, and they passed.
    • [x] All extensions have a clear comments explaining their functionality, all parameters and return type in English.
    • [x] All extensions are declared as public.
    • [x] I have added a changelog entry describing my changes.
    opened by JayMehta97 17
  • Use 'swift_version' instead of 'pod_target_xcconfig{SWIFT_VERSION}' t…

    Use 'swift_version' instead of 'pod_target_xcconfig{SWIFT_VERSION}' t…

    …o specify Swift version of pod target itself.

    Checklist

    • [x] I checked the Contributing Guidelines before creating this request.
    • [ ] New extensions are written in Swift 4.
    • [ ] New extensions support iOS 8.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+.
    • [ ] I have added tests for new extensions, and they passed.
    • [ ] All extensions have a clear comments explaining their functionality, all parameters and return type in English.
    • [ ] All extensions are declared as public.
    • [ ] I have added a changelog entry describing my changes.
    opened by dklinzh 17
  • Add stack function to array with element UIView

    Add stack function to array with element UIView

    Adding the function to create a UIStackView from an Array of UIViews. Taking the defaults and parameter docs from Apples Defaults.

    Solves #399

    Checklist

    • [x] I checked the Contributing Guidelines before creating this request.
    • [x] New extensions are written in Swift 4.
    • [x] New extensions support iOS 8.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+.
    • [x] I have added tests for new extensions, and they passed.
    • [x] All extensions have a clear comments explaining their functionality, all parameters and return type in English.
    • [x] All extensions are declared as public.
    • [x] I have added a changelog entry describing my changes.
    opened by be-meyer 16
  • Update LICENSE copyright date to 2018

    Update LICENSE copyright date to 2018

    https://github.com/SwifterSwift/SwifterSwift/blob/master/LICENSE

    MIT License
    -- Copyright (c) 2015-2017 SwifterSwift (https://github.com/swifterswift)
    ++ Copyright (c) 2015-2018 SwifterSwift (https://github.com/swifterswift)
    
    help wanted good first issue documentation 
    opened by SD10 16
  • String [safeFrom:] and [safeTo:]

    String [safeFrom:] and [safeTo:]

    🚀

    Hello. Thank you for SwifterSwift. Fix #1066.

    Checklist

    • [x] I checked the Contributing Guidelines before creating this request.
    • [x] New extensions are written in Swift 5.0.
    • [x] New extensions support iOS 10.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+, or use @available if not.
    • [x] I have added tests for new extensions, and they passed.
    • [x] All extensions have a clear comments explaining their functionality, all parameters and return type in English.
    • [x] All extensions are declared as public.
    • [x] I have added a changelog entry describing my changes.
    opened by RomanPodymov 2
  • String [safeFrom:] and [safeTo:]

    String [safeFrom:] and [safeTo:]

    🚀 Is your feature request related to a problem? Please describe. Hello. Thank you for SwifterSwift. Found out that you have s[safe: 10] and s[safe: 1..<10]. But what about s[safeFrom: 3] and s[safeTo: 10]?

    Describe the solution you'd like Add subscript(safeFrom lowerBound: Int) -> String? and subscript(safeTo upperBound: Int) -> String? to StringExtensions.swift.

    Describe alternatives you've considered Nothing.

    Additional context Nothing.

    opened by RomanPodymov 0
  • add a more simple conversion between string and double.

    add a more simple conversion between string and double.

    Checklist

    • [x] I checked the Contributing Guidelines before creating this request.
    • [x] New extensions are written in Swift 5.0.
    • [x] New extensions support iOS 10.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+, or use @available if not.
    • [x] I have added tests for new extensions, and they passed.
    • [x] All extensions have a clear comments explaining their functionality, all parameters and return type in English.
    • [x] All extensions are declared as public.
    • [x] I have added a changelog entry describing my changes.
    opened by westfort4July 0
  • Fixes building HKActivitySummary for macOS

    Fixes building HKActivitySummary for macOS

    🚀 fixes #1054

    Checklist

    • [x] I checked the Contributing Guidelines before creating this request.
    • [x] New extensions are written in Swift 5.0.
    • [x] New extensions support iOS 10.0+ / tvOS 9.0+ / macOS 10.10+ / watchOS 2.0+, or use @available if not.
    • [x] I have added tests for new extensions, and they passed.
    • [x] All extensions have a clear comments explaining their functionality, all parameters and return type in English.
    • [x] All extensions are declared as public.
    • [x] I have added a changelog entry describing my changes.
    opened by guykogus 2
  • SwifterSwift breaks compilation on macOS projects targeting BigSur and above and using the latest Xcode SDK

    SwifterSwift breaks compilation on macOS projects targeting BigSur and above and using the latest Xcode SDK

    Describe the bug SwifterSwift declares an extension to HealthKit that breaks compilation on macOS because Healthkit is only available on macOS from v13

    To Reproduce Steps to reproduce the behavior:

    1. Create a project on Xcode 14 on Ventura and try to include SwifterSwift with a target deployment < Ventura

    Expected behavior Code should compile

    Desktop (please complete the following information):

    • OS: macOS 13
    • Xcode Version : 14.1
    • Project: deployment = BigSur and uses macOS13 SDK to compile

    Additional context We created a fork and simply modified the @availability predicate in HKActivitySummaryExtensions

    @available(watchOS 2.2, macOS 13.0, *)

    confirmed bug: source help wanted good first issue 
    opened by spicymatt 0
  • Random String duplication

    Random String duplication

    We have 2 basically the same functions for generating a random string which only differ in their signatures.

    https://github.com/SwifterSwift/SwifterSwift/blob/04d474ade1aa7d8e6bde9a65d5f8d1a3595dc3a0/Sources/SwifterSwift/SwiftStdlib/StringExtensions.swift#L764-L778

    and

    https://github.com/SwifterSwift/SwifterSwift/blob/04d474ade1aa7d8e6bde9a65d5f8d1a3595dc3a0/Sources/SwifterSwift/SwiftStdlib/StringExtensions.swift#L1159-L1177

    I suggest we only leave the static one, so it will be the same as Int.random(in:) in Foundation

    opened by viktart 0
Releases(5.3.0)
Owner
SwifterSwift
We Make Swift, well, Swifter 😎
SwifterSwift
Collection of Swift-extensions to boost development process.

SwiftBoost Collection of Swift-extensions to boost development process. Community Installation Ready to use on iOS 13+, tvOS 13+, watchOS 6.0+. Swift

Sparrow Code 119 Dec 20, 2022
SharkUtils is a collection of Swift extensions, handy methods and syntactical sugar that we use within our iOS projects at Gymshark.

SharkUtils is a collection of Swift extensions, handy methods and syntactical sugar that we use within our iOS projects at Gymshark.

Gymshark 1 Jul 6, 2021
A handy collection of Swift method and Tools to build project faster and more efficient.

SwifterKnife is a collection of Swift extension method and some tools that often use in develop project, with them you might build project faster and

李阳 4 Dec 29, 2022
Handy Combine extensions on NSObject, including Set.

Storable Description If you're using Combine, you've probably encountered the following code more than a few times. class Object: NSObject { var c

hcrane 23 Dec 13, 2022
XCMetrics is the easiest way to collect Xcode build metrics and improve developer productivity.

XCMetrics is the easiest way to collect Xcode builds metrics and improve your developer productivity. Overview ?? Keep your build times under control

Spotify 989 Jan 2, 2023
TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app.

TypeStyle TypeStyle is a handy app for iPhone and iPad that generates text using different styles and decorations. It is a native Swift iOS app. Featu

Eugene Belinski 31 Dec 14, 2022
A Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and other native frameworks.

ZamzamKit ZamzamKit is a Swift package for rapid development using a collection of micro utility extensions for Standard Library, Foundation, and othe

Zamzam Inc. 261 Dec 15, 2022
BFKit-Swift is a collection of useful classes, structs and extensions to develop Apps faster.

Features • Classes and Extensions Compatibility • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog • Exa

Fabrizio Brancati 992 Dec 2, 2022
An open source Instapaper clone that features apps and extensions that use native UI Components for Mac and iOS.

TODO: Screenshot outdated Hipstapaper - iOS and Mac Reading List App A macOS, iOS, and iPadOS app written 100% in SwiftUI. Hipstapaper is an app that

Jeffrey Bergier 51 Nov 15, 2022
Useful Swift code samples, extensions, functionalities and scripts to cherry-pick and use in your projects

SwiftyPick ?? ?? Useful Swift code samples, extensions, functionalities and scripts to cherry-pick and use in your projects. Purpose The idea behind t

Manu Herrera 19 May 12, 2022
Extensions giving Swift's Codable API type inference super powers 🦸‍♂️🦹‍♀️

Welcome to Codextended — a suite of extensions that aims to make Swift’s Codable API easier to use by giving it type inference-powered capabilities an

John Sundell 1.4k Jan 2, 2023
🌤 Swift Combine extensions for asynchronous CloudKit record processing

Swift Combine extensions for asynchronous CloudKit record processing. Designed for simplicity.

Chris Araman 46 Dec 8, 2022
Useful extensions for my Swift code

UIViewController extensions presentAlert(withTitle title: String, message : String) presentAlertDialog(withTitle title: String, message : String, acti

Bogdan Grafonsky 1 Oct 17, 2021
Personally useful Swift Extensions for iOS Development

Useful-Swift-Extensions Personally useful Swift Extensions for iOS Development; cobbled together from a variety of development projects and StackOverf

Nick Arner 5 Dec 13, 2021
Swift extensions for asynchronous CloudKit record processing

⛅️ AsyncCloudKit Swift extensions for asynchronous CloudKit record processing. D

Chris Araman 17 Dec 8, 2022
Extensions for Swift Standard Types and Classes

Cent Cent is a library that extends certain Swift object types using the extension feature and gives its two cents to Swift language. Dollar is a Swif

Ankur Patel 225 Dec 7, 2022
Useful functions and extensions for sorting in Swift

SwiftSortUtils Motivation This library takes a shot at making comparing and sorting in Swift more pleasant. It also allows you to reuse your old NSSor

Daniel Strittmatter 60 Sep 9, 2022
A μframework of extensions for SequenceType in Swift 2.0, inspired by Python's itertools, Haskell's standard library, and other things.

SwiftSequence Full reference here. (If you're looking for data structures in Swift, those have been moved to here) SwiftSequence is a lightweight fram

Donnacha Oisín Kidney 376 Oct 12, 2022
Librairie publique des extensions fréquemment utilisées en Swift.

SwiftLib Statut du projet ?? Ce projet est actuellement en cours de construction. Toute contribution est la bienvenue ! Description ?? Contient les ex

Niji Digital 2 Oct 24, 2022