Latest 1.0.0
Homepage https://github.com/alexshubin/Simplify
License MIT
Platforms ios 8.0
Authors

Version
License
Platform

My ‘go to’ pack of Swift extensions of most usable Foundation and UIKit classes.

Installation

Simplify is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "Simplify"

Usage

Dictionary

Compose dictionaries

var dict = ["one":1]
dict += ["two":2] + ["three":3] //["two": 2, "one": 1, "three": 3]

UIView

Make view border with round corners

myView.makeRoundBorder(ofColor: .black, width: 1, radius: 3)

Add constraints to view

myView.addConstaintsToSuperview(leftOffset: 0, topOffset: 0)
myView.addConstaints(height: 64, width: 64)

Take a screenshot of your view

let screenshot:UIImage = myView.snapshotImage

UIViewController

Take content view controller of your navigation controller if needed

let contentVC = destinationVC.contentViewController

Data

Build data in current Calendar with single method and take date components

let dt = Date.from(year: 2017, month: 6, day: 25, hour: 12)
dt.month // 6
dt.year // 2017

Collection

Safe collection subscript – returns optional

let optionalElement = array[safe: 15]

UIImage

Make UIImage of color with rounded corners

let image = UIImage.ofColor(.red, size: size, cornerRadius: 5)

Create gradient image

let gradient = Gradient(direction:.leftRight, size:CGSize(width:50, height:10), startColor:.red, endColor:.yellow)
let gradientImage = UIImage.gradientImage(gradient)

Gaussian blur for UIImage with radius:

let imageWithBlur = myImage.blurImage(radius: 8)

Get pixel color for image

let color = myImage.pixelColor(for: CGPoint(x:10, y:10))

Transform image to single color template

let maskedImage = myImage.maskWithColor(color: .blue)

Crop image to sqare

let cropped = myImage.squareCroppedImage()

Scale image to size

let resized = myImage.scaledTo(size:mySize)

String

Get right endings for russian countable nouns

for i in 1...7 {
print(String(i)+" "+String.russianWordFor(number: i, one: "яйцо", two: "яйца", five: "яиц"))
}

Output:

1 яйцо
2 яйца
3 яйца
4 яйца
5 яиц
6 яиц
7 яиц

Generate an image from string

let myImage = "STR".generateImage(of: CGSize(width:50,height:50), font: UIFont.systemFont(ofSize: 10), color: .red)

NSAttributedString

Easily create NSAttributedString

let attrStr = NSAttributedString(string: "STR", font: font.withSize(10), color: .red)

Author

Alex Shubin

License

Simplify is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Simplify",
    "version": "1.0.0",
    "summary": "GoTo Extensions",
    "description": "Extensions for:n- Dictionaryn- UIViewn- UIViewControllern- Daten- Arrayn- UIImagen- String",
    "homepage": "https://github.com/alexshubin/Simplify",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "[email protected]": "[email protected]"
    },
    "source": {
        "git": "https://github.com/alexshubin/Simplify.git",
        "tag": "1.0.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Simplify/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This