https://github.com/christopherkarani/this
🌋 Powerful, Clean, Elegant Initialisation
https://github.com/christopherkarani/this
closure protocol-oriented swift
Last synced: 10 months ago
JSON representation
🌋 Powerful, Clean, Elegant Initialisation
- Host: GitHub
- URL: https://github.com/christopherkarani/this
- Owner: christopherkarani
- License: mit
- Created: 2017-12-07T11:18:39.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-12-10T20:14:47.000Z (about 8 years ago)
- Last Synced: 2025-03-25T21:05:51.000Z (10 months ago)
- Topics: closure, protocol-oriented, swift
- Language: Swift
- Homepage:
- Size: 26.4 KB
- Stars: 1
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# This
🌋 Powerful, Clean, Elegant Initialisation Sugar 🌋
# Description
This is a small syntactic extension to NSObject that makes it easier for you to initilialize your object in a very Swifty way.
## Simply
- `this()` is an extension on all NSObject subclasses
```swift
let fileManager = FileManager().this {
$0.urls(for: .applicationDirectory, in: .userDomainMask)
}
```
Clean up your initialization Code
```swift
let tableView = UITableView().this {
$0.backgroundColor = .white
$0.register(UserCell.self, forCellReuseIdentifier: "CellID")
$0.separatorStyle = .none
$0.allowsSelection = false
}
```
Initialize in **this** way.
```swift
let tableView : UITableView = {
let table = UITableView()
table.backgroundColor = .white
table.register(UserCell.self, forCellReuseIdentifier: "CellID")
table.separatorStyle = .none
table.allowsSelection = false
return table
}()
```
### Easy Customization
- Use your own Types With a simple Extension
```swift
extension CustomType: This {}
let instance = CustomType().this {
$0.color = .blue
$0.label.text = "Custom Type"
}
```
### A Real World Example
```swift
class LoginViewController : UIViewController {
var loginButton = UIButton().this {
$0.setTitle("Login", for: .normal)
$0.backgroundColor = . yellow
$0.layer.masksToBounds = true
$0.layer.cornerRadius = 5
}
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(loginButton)
}
}
```
### Installing
- **For iOS 8+ projects** with [CocoaPods](https://cocoapods.org):
```ruby
pod 'This'
## Deployment
just `clone` the repo and run on Xcode
## Contributing
Please read [CONTRIBUTING.md](https://github.com/chrisbkarani/This/blob/master/Contribution.md) for details on our code of conduct, and the process for submitting pull requests to us.
## Authors
* **Chris Karani** -
## License
This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/chrisbkarani/This/blob/master/LICENSE) file for details