Simplify 1.0.0

Simplify 1.0.0

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Jul 2017
SwiftSwift Version 3.0
SPMSupports SPM

Maintained by Alex Shubin.


Downloads

Total3
Week0
Month0

Installs

Apps2
Test Targets1
powered by Segment

GitHub

Stars2
Watchers2
Forks1
Issues0
Contributors1
Pull Requests0

Code

Files8
LOCLines of Code 244


Simplify 1.0.0

Simplify

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.