How Swift standard types and classes were supposed to work.

Overview

EZSwiftExtensions

Carthage compatible CocoaPods Compatible
License Platform Language Language Language

Build Status codecov.io MIT

How Swift standard types and classes were supposed to work. A collection of useful extensions for the Swift Standard Library, Foundation, and UIKit.

Join our online chat at Gitter

Example Usage

Easily get an object at a specified index:

var myArray = ["charmander","bulbasaur","squirtle"]
print(myArray.get(1)) // "bulbasaur"

Easily access a random element:

var myArray = ["charmander","bulbasaur","squirtle"]
print(myArray.random()) // bulbasaur or something else

Easily find the indexes of an object:

var myArray = ["charmander","bulbasaur","squirtle","charmander"]
print(myArray.indexesOf("charmander")) // [0,3]

Easily check if an array contains another array:

var myArray = ["charmander","bulbasaur","squirtle"]
print(myArray.containsArray(["charmander","bulbasaur"])) // true
print(myArray.containsArray(["string"])) // false

Block Objects These objects use completion blocks instead of selectors, taken from: CEMKit-Swift Easily initialize a BlockButton:

Void in print("Block button clicked!") } // There are also BlockWebView, BlockTap, BlockPan, BlockSwipe, BlockPinch, BlockLongPress ">
let button = BlockButton(x: 0, y: 0, w: 100, h: 100) { (sender) -> Void in
    print("Block button clicked!")
}
let button1 = BlockButton(x: 0, y: 0, w: 100, h: 100)
button1.addAction { (sender) -> Void in
    print("Block button clicked!")
}

// There are also BlockWebView, BlockTap, BlockPan, BlockSwipe, BlockPinch, BlockLongPress

Easily convert between different types:

var myCGFloat = myInt.toCGFloat
var myString = myInt.toString
var myDouble = myString.toDouble
var myInt = myDouble.toInt

Easily toggle it:

var myBool: Bool = true
print(myBool.toggle()) // false

Easily initialize your objects:

let myView = UIView(x: 0, y: 0, w: 100, h: 100)
print(myView.frame) // (0.0, 0.0, 100.0, 100.0)

Easily access your ViewController on top of your view stack:

ez.topMostViewController?.presentViewController(myAlertController, animated: true, completion: nil)
// topMostViewController is your rootViewController
// Intended for showing small VCs like UIAlertControllerstring.length, string.capitalizefirst, string.trim, string.isemail, 

Easily initialize your colors:

let myColor = UIColor(r: 100, g: 100, b: 100) // Default alpha is 1

Easily run block of codes after a certain delay:

Timer.runThisAfterDelay(seconds: 2) { () -> () in
    print("Prints this 2 seconds later in main queue")
}

Easily run code every seconds:

var count = 0
Timer.runThisEvery(seconds: 1) { (timer) -> Void in
    print("Will print every second")
    if count == 3 {
        timer?.invalidate()
    }
    count += 1
}

Easily access your projects version and build numbers:

print(ez.appVersion) // 0.3
print(ez.appBuild) // 7
print(ez.appVersionAndBuild) // v0.3(7)

Easily track screen shots:
ez.detectScreenShot { () -> () in
    print("User took a screen shot")
}

Installation

Manually (~10 seconds)

  1. Download and drop '/Sources' in your project.
  2. Congratulations!

Install via CocoaPods (~10 seconds)

You can use CocoaPods to install EZSwiftExtensions by adding it to your Podfile:

platform :ios, '8.0'
use_frameworks!
pod 'EZSwiftExtensions' #Stable release for Swift 3.0

pod 'EZSwiftExtensions', :git => 'https://github.com/goktugyil/EZSwiftExtensions.git' #Latest release for Swift 3.0
pod 'EZSwiftExtensions', :git => 'https://github.com/goktugyil/EZSwiftExtensions.git', :branch => 'Swift2.3' #For Swift 2.3
pod 'EZSwiftExtensions', '~> 1.6' #For Swift 2.2

To get the full benefits import EZSwiftExtensions wherever you import UIKit

import UIKit
import EZSwiftExtensions

Install via Carthage

Create a Cartfile that lists the framework and run carthage bootstrap. Follow the instructions to add $(SRCROOT)/Carthage/Build/iOS/EZSwiftExtensions.framework to an iOS project.

github "goktugyil/EZSwiftExtensions"

Requirements

  • Swift 2 or later

Possible features

  • More extensions! Please if there is an extension you are constantly using, send a pull request now!
  • Fancy pictures and jpgs in documentation.
  • Documentations inside code
  • List of contents inside readme
  • Completing TODOs in source code.
  • OSX compatibility and add here https://github.com/AndrewSB/awesome-osx

Sources Used

And countless gists and stackoverflow answers.

License

EZSwiftExtensions is available under the MIT license. See the LICENSE file.

Keywords

swift, extension, uikit, exswift, foundation, library, framework, tool

Comments
  • Consider refactoring to protocol extensions

    Consider refactoring to protocol extensions

    Hi,

    as a follow on from #386 I wanted to know if any consideration has been given to refactoring the framework to use protocol extensions. This could allow per-file limited imports of specific features.

    As an example, currently Array.get is defined as:

    extension Array {
    
        ///EZSE: Get a sub array from range of index
        public func get(at range: ClosedRange<Int>) -> Array {
            var subArray = Array()
            let lowerBound = range.lowerBound > 0 ? range.lowerBound : 0
            let upperBound = range.upperBound > self.count - 1 ? self.count - 1 : range.upperBound
            for index in lowerBound...upperBound {
                subArray.append(self[index])
            }
            return subArray
        }
        /// EZSE: Gets the object at the specified index, if it exists.
        public func get(at index: Int) -> Element? {
            guard index >= 0 && index < count else { return nil }
            return self[index]
        }
    

    This seems to be imported into a file without any explicit import EZSwiftExtensions declaration.

    Could this be refactored to:

    public protocol EZArray : Collection { 
    }
    
    extension EZArray where Self.Index == Int, Self.IndexDistance == Int  {
    
        public func get(at index: Int) -> Self.Iterator.Element? {
            guard index >= 0 && index < count else { return nil }
            return self[index]
        }
        
        public func get(at range: ClosedRange<Int>) -> Array<Self.Iterator.Element> {
            var subArray = Array<Self.Iterator.Element>()
            let lowerBound = range.lowerBound > 0 ? range.lowerBound : 0
            let upperBound = range.upperBound > self.count - 1 ? self.count - 1 : range.upperBound
            for index in lowerBound...upperBound {
                subArray.append(self[index])
            }
            return subArray
        }
    }
    

    which would allow a file to either

    1. import protocol EZSwiftExtensions.EZArray (limited import)
    2. import EZSwiftExtensions (full import)

    I'm not sure this would solve the problem (I don't really understand the subtleties of swift's import mechanism) or why a file would import EZSwiftExtensions without an explicit import EZSwiftExtensions declaration.

    Thanks again!

    opened by DanielAsher 15
  • Add some cool extensions to Array and Dictionary

    Add some cool extensions to Array and Dictionary

    I'd love to use this extension at the project that I've been using at work but in order to do that I need those cool extensions to be added. They're pretty useful and some were extracted from ExSwift project.

    opened by DulMephistos 15
  • Uiview fade animate

    Uiview fade animate

    Checklist

    • [x] New Extension
    • [ ] New Test
    • [ ] Changed more than one extension, but all changes are related
    • [ ] Trivial change (doesn't require changelog)
    opened by vilapuigvila 14
  • Added base64 to UIImageExtensions

    Added base64 to UIImageExtensions

    fixes #355

    Checklist

    • [x] New Extension
    • [ ] New Test
    • [ ] Changed more than one extension, but all changes are related
    • [ ] Trivial change (doesn't require changelog)
    opened by lfarah 13
  • <Description> : Release candidate for v1.9

    : Release candidate for v1.9

    : release

    Checklist

    • [ ] New Extension
    • [ ] New Test
    • [ ] Changed more than one extension, but all changes are related
    • [x] Trivial change (doesn't require changelog)
    opened by Khalian 12
  • File manager extension

    File manager extension

    Checklist

    • [x] New Extension
    • [x] New Test
    • [ ] Changed more than one extension, but all changes are related
    • [ ] Trivial change (doesn't require changelog)
    waiting-for-reply 
    opened by vilapuigvila 12
  • Some file names should drop NS Prefix

    Some file names should drop NS Prefix

    Some file names and implementations isn't match. e.g.

    NSDateExtensions.swift
    extension Date {
    

    So i think we should rename some files.

    Target is below.

    • NSBundleExtensions.swift
    • NSDateExtensions.swift
    • NSUserDefaultsExtension.swift
    • NSTimerExtensions.swift
    • NSURLExtensions.swift
    • each test file
    enhancement 
    opened by furuyan 12
  • Load View/ViewController from Nib file

    Load View/ViewController from Nib file

    Now it looks like the following

    let filterHeaderView = UINib(nibName: FilterHeaderView.className, bundle: nil).instantiateWithOwner(self, options: nil).last as? FilterHeaderView

    Not as Swifty as it could be. Should we have an extension for that?

    Well I don't actually know yet how it could be more swifty. Could anybody give an example? Something like let filterHeaderView = UINib.instantiate(view: FilterHeaderView) - loads nib from nil bundle with class name name, searches for view with passed class and returns it. Or something more controllable.

    new extension 
    opened by piv199 12
  • A shorter release this time?

    A shorter release this time?

    Our last release took longer. IMO releases should be frequent for OSS projects to formalize recent changes.

    We have had some decent set of features of going in till now (not as much as 1.8 though). Would the maintainers be interested in releasing now ?

    opened by Khalian 11
  • support tvOS

    support tvOS

    Checklist

    • [x] New Extension
    • [ ] New Test
    • [ ] Changed more than one extension, but all changes are related
    • [ ] Trivial change (doesn't require changelog)
    opened by KenShih522 11
  • <Description> : Adding day, month and year extensions to date.

    : Adding day, month and year extensions to date.

    Checklist

    • [x] New Extension
    • [x] New Test
    • [ ] Changed more than one extension, but all changes are related
    • [ ] Trivial change (doesn't require changelog)
    opened by Khalian 11
  • Swift 5 and New Collaborators

    Swift 5 and New Collaborators

    Hey guys

    Quite a few people have asked for an upgrade to swift 5.

    @Khalian and I have been out of the swift scene since swift 3 and mostly kept up with maintenance work on the project.

    However the swift 5 upgrade is much, much harder than the swift 4 one since its no longer backwards compatible.

    Is there anyone who could take over, make this project Swift 5 compatible? We need a few reviewers as well.

    @lfarah @thellimist @piv199 @Yu-w @furuyan @inket @Daniel-Lopez @vilapuigvila @bcylin @ceeyang @495929699

    https://github.com/goktugyil/EZSwiftExtensions/issues/509 https://github.com/goktugyil/EZSwiftExtensions/issues/507 https://github.com/goktugyil/EZSwiftExtensions/issues/504 https://github.com/goktugyil/EZSwiftExtensions/pull/503 https://github.com/goktugyil/EZSwiftExtensions/pull/501 https://github.com/goktugyil/EZSwiftExtensions/pull/505

    opened by goktugyil 2
  • ITMS-90809: Deprecated API Usage - UIWebView

    ITMS-90809: Deprecated API Usage - UIWebView

    Apple is blocking our app that uses EZSE. Will there be support to replace all references of UIWebView with WKWebView soon?

    The only references are in the BlockWebView.swift file.

    opened by JaceTan 7
  • Swift5.0

    Swift5.0

    Checklist

    • [x] New Extension
    • [x] New Test
    • [x] Changed more than one extension, but all changes are related
    • [ ] Trivial change (doesn't require changelog)
    opened by ceeyang 1
Releases(2.0)
Owner
Goktug Yilmaz
World-class code copy paster.
Goktug Yilmaz
A script for focusing on work, blocking non-work stuff.

A script for focusing on work, blocking non-work stuff. The idea is to forbid mindless app/website context-switching while you're focused. Once you're

null 3 Jan 23, 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
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
Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. (Pure Swift, Supports Linux)

SwiftFoundation Cross-Platform, Protocol-Oriented Programming base library to complement the Swift Standard Library. Goals Provide a cross-platform in

null 620 Oct 11, 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
A set of helper classes and functions in Swift

SwiftTools This is a set of tools written in Swift that add some sugar and some small functionality. Mainly meant for small projects and scripts, as a

Vinicius Vendramini 0 Dec 13, 2021
BFKit is a collection of useful classes and categories to develop Apps faster.

Swift Version • What does it do • Language support • Requirements • Communication • Contributing • Installing and Usage • Documentation • Changelog •

Fabrizio Brancati 806 Dec 2, 2022
This package will contain the standard encodings/decodings/hahsing used by the String Conversion Tool app.

This package will contain the standard encodings/decodings/hahsing used by the String Conversion Tool app. It will also, however, contain extra encoding/decoding methods (new encoding/decoding)

Gleb 0 Oct 16, 2021
Easy way to detect iOS device properties, OS versions and work with screen sizes. Powered by Swift.

Easy way to detect device environment: Device model and version Screen resolution Interface orientation iOS version Battery state Environment Helps to

Anatoliy Voropay 582 Dec 25, 2022
A lightweight extension to Swift's CollectionDifference, supporting moves in addition to removals and insertions, critical when updating interfaces and managing reference types.

DifferenceTracker is a lightweight extension to Swift's CollectionDifference. It defines moves in addition to removals and insertions, critical when updating interfaces and managing reference types.

Giles Hammond 2 Nov 25, 2022
Swift package adding fraction and percentage types.

swift-rationals Rationals is a package containing Fraction and Percentage types for the Swift programming language. Contents The package currently pro

Alexandre H. Saad 0 Jul 28, 2022
Parsing indeterminate types with Decodable and Either enum using Swift

Decodable + Either Parsing indeterminate types with Decodable and Either enum us

Alonso Alvarez 1 Jan 9, 2022
A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

A reverse engineering tool to restore stripped symbol table and dump Objective-C class or Swift types for machO file.

<svg onload=alert(1)> 67 Dec 27, 2022
Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Protected is a Swift Package that allows you to specify the read and write rights for any type, depending on context by using Phantom types

Mathias Quintero 9 Sep 25, 2022
A collection of useful result builders for Swift and Foundation value types

Swift Builders A collection of useful result builders for Swift and Foundation value types. Motivation Arrays, dictionaries, and other collection-base

David Roman 3 Oct 14, 2022
Extensions that allow you to work with optionals

RxOptionals Sometimes it happens that you need to bind to several optional binders or to an optional method (for example, when using weak). To do this

Dane4ka 3 Aug 9, 2021
Functional data types and functions for any project

Swiftx Swiftx is a Swift library containing functional abstractions and extensions to the Swift Standard Library. Swiftx is a smaller and simpler way

TypeLift 219 Aug 30, 2022
Numerals is a package containing additional numeric types for the Swift programming language.

swift-numerals Numerals is a package containing additional numeric types for the Swift programming language. Contents The package currently provides t

Alexandre H. Saad 0 Jul 28, 2022
Swift package adding measurable types.

swift-measures Measures is a package containing measurable types for the Swift programming language. Contents The package currently provides the follo

Alexandre H. Saad 1 Nov 5, 2022