Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshdholtz/rekt-swift
Functional approach to altering CGRect
https://github.com/joshdholtz/rekt-swift
Last synced: about 1 month ago
JSON representation
Functional approach to altering CGRect
- Host: GitHub
- URL: https://github.com/joshdholtz/rekt-swift
- Owner: joshdholtz
- License: mit
- Created: 2015-12-04T06:53:27.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2015-12-04T08:28:32.000Z (about 9 years ago)
- Last Synced: 2024-11-10T15:52:01.572Z (2 months ago)
- Language: Swift
- Homepage:
- Size: 21.5 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Rekt-Swift
Functional approach to altering CGRect[![Carthage Compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)
## 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" :blush:
### Ugly Way
```swift
var rect = someFrame
rect.origin.x += 10
rect.origin.y += 5
rect.size.width = 200
rect.size.height = 100
```### Good Looking Way
```swift
// 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](https://github.com/Carthage/Carthage) is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
You can install Carthage with [Homebrew](http://brew.sh/) using the following command:
```bash
$ brew update
$ brew install carthage
```To integrate Rekt into your Xcode project using Carthage, specify it in your `Cartfile`:
```ogdl
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
```swift
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
```swift
let rect = someFrame.alter({ (x, y, width, height) -> Void in
x += 10
y += 5
width = 200
height = 100
return
})
```### Alter Individual By Chaining
```swift
let rect = someFrame.alterX({$0+10})
.alterY({$0+5})
.alterWidth({$0+200})
.alterHeight({$0+100})
```### Alter Individual By Value
```swift
let rect = someFrame.alterX(10)
.alterY(5)
.alterWidth(200)
.alterHeight(100)
```## Author
Josh Holtz, [email protected], [@joshdholtz](https://twitter.com/joshdholtz)
## License
`Rekt-Swift` is available under the MIT license. See the LICENSE file for more info.