Coder Social home page Coder Social logo

rekt-swift's Introduction

Rekt-Swift

Functional approach to altering CGRect

Carthage Compatible

Features

  • Alter CGRect in a more functional and declarative way
    • Alter everything at once (x, y, width, height)
    • Or alter by chaining individual calls for each

Quick Example

Replay the "Ugly Way" with the "Good Looking Way" ๐Ÿ˜Š

Ugly Way

var rect = someFrame
rect.origin.x += 10
rect.origin.y += 5
rect.size.width = 200
rect.size.height = 100

Good Looking Way

// Alter x, y, width, and height all at once
// Return a tuple of (x,y,width,height)
let rect = someFrame.alter { (x, y, width, height) -> Rekt in
	(x+10,y+5,200,100)
}

// Chain calls for x, y, width, and height together
// Each x, y, width, and height have a function that
// takes a closure and one that takes a value
let rect = someFrame.alterX({$0+10})
	.alterY({$0+5})
	.alterWidth(200)
	.alterHeight(100)

Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

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

github "joshdholtz/Rekt-Swift" "master"

Run carthage to build the framework and drag the built Rekt.framework into your Xcode project.

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate Rekt into your project manually by copying and pasting all the files in the Classes directory.

Usage

Alter All

let rect = someFrame.alter { (x, y, width, height) -> Rekt in
	(x+10,y+5,200,100)
}

Alter All (inout)

  • Uses inout variables instead of returning tuple
  • Don't need to modify all variables
let rect = someFrame.alter({ (x, y, width, height) -> Void in
	x += 10
	y += 5
	width = 200
	height = 100
	return
})

Alter Individual By Chaining

let rect = someFrame.alterX({$0+10})
	.alterY({$0+5})
	.alterWidth({$0+200})
	.alterHeight({$0+100})

Alter Individual By Value

let rect = someFrame.alterX(10)
	.alterY(5)
	.alterWidth(200)
	.alterHeight(100)

Author

Josh Holtz, [email protected], @joshdholtz

License

Rekt-Swift is available under the MIT license. See the LICENSE file for more info.

rekt-swift's People

Stargazers

Josh Holtz avatar

Watchers

Josh Holtz avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.