🍯 Powerful, Elegant Syntactical Sugar for Swift 🍯
Enjoy Beutiful Syntactic Enhancements to your swift code base
let fileManager = FileManager().this {
$0.urls(for: .applicationDirectory, in: .userDomainMask)
}
let tableView : UITableView = { let table = UITableView() table.backgroundColor = .white table.register(UserCell.self, forCellReuseIdentifier: "CellID") table.separatorStyle = .none table.allowsSelection = false return table }()
let tableView = UITableView().this { $0.backgroundColor = .white $0.register(UserCell.self, forCellReuseIdentifier: "CellID") $0.separatorStyle = .none $0.allowsSelection = false }
let point = CGPoint().set { $0.x = 100 $0.y = 200 }
extension CustomType: Sukari {} let instance = CustomType().this { $0.color = .blue $0.label.text = "Custom Type" }
class LoginViewController : UIViewController { var loginButton = UIButton().this { $0.setTitle("Login", for: .normal) $0.backgroundColor = . yellow $0.layer.masksToBounds = true $0.layer.cornerRadius = 5 } let emailTextField = UITextField().this { $0.placeholder = "Email" $0.borderStyle = .roundedRect $0.font = UIFont.systemFont(ofSize: 14) $0.backgroundColor = UIColor(white: 0, alpha: 0.03) } override func viewDidLoad() { super.viewDidLoad() view.addSubview(loginButton) view.addSubview(emailTextField) } }
Unwrap lets you easily require Optional values.
Use unwrap() on any optional that you expect to always be non-nil, or else crash your App with a more (optional) descriptive debug message with .unwrap(debug:)
On top of that, unwrap also provides a sytactic enhancement to easily unwrap optionals through an under-the-hood Guard Statement.
- No More
ifletpyramids andGuardletTowers. only a clean and simple extension to your optionalsunwrap - Recieve Rich Debug Information with
unwrap(debug:)
Call unwrap() on any Optional, optionally giving a debugMessage for debugging purposes:
struct Person { let name: String let email: String init(dictionary: [String: Any]) { name = dictionary["name"].unwrap(debug: "Unable to find json Element Name") as! String email = dictionary["email"].unwrap(debug: "Unable to find json Element Email") as! String } } let dictionary = ["ame": "Chris", "email": "[email protected]"] let chris = Person(dictionary: dictionary) print(chris.name) //Chris print(chris.email) // [email protected]
class LoginController: UIViewController { var token: Token? override func viewDidLoad() { super.viewDidLoad() // more code is more bugs guard let unwrappedToken = token else { // if this crashes we enter a 'nil' state in our app with no debug information return } LoginService.login(unwrappedToken) } }
class LoginController: UIViewController { var token: Token? override func viewDidLoad() { super.viewDidLoad() LoginService.login(token.unwrap()) } }
- For iOS 8+ projects with CocoaPods:
pod 'Sukari'
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
This project is licensed under the MIT License - see the LICENSE.md file for details

