Latest 0.2.1
Homepage https://github.com/chrisbkarani/Sukari
License MIT
Platforms ios 8.0, osx 10.9, watchos 2.0, tvos 9.0
Frameworks Foundation, CoreGraphics
Authors



🍯 Powerful, Elegant Syntactical Sugar for Swift 🍯

Description

Enjoy Beutiful Syntactic Enhancements that will save you Hundreds Or Thousands of lines of Code

Simply add Sukari to your initializers

  • this() is an extension on all NSObject subclasses

    let fileManager = FileManager().this {
       $0.urls(for: .applicationDirectory, in: .userDomainMask)
    }

Clean up your initialization Code

  let tableView : UITableView = {
      let table = UITableView()
      table.backgroundColor = .white
      table.register(UserCell.self, forCellReuseIdentifier: "CellID")
      table.separatorStyle = .none
      table.allowsSelection = false
      return table
  }()

Initialize in this way.

let tableView = UITableView().this {
    $0.backgroundColor = .white
    $0.register(UserCell.self, forCellReuseIdentifier: "CellID")
    $0.separatorStyle = .none
    $0.allowsSelection = false
}

Easily copy value Types

Easy Customization

Use your own Types With a simple Extension

extension CustomType: Sukari {}

let instance = CustomType().this {
      $0.color = .blue
      $0.label.text = "Custom Type"
 }

A Real World Example

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

Unwrap lets you easily require Optional values to be non-nil, or crash with ease.

Often Times you have to handle many optionals in your code Using Guard or If let in order to unwrap optional values in your code.
This Has Two Problems.

  1. It Causes Code Congestion, making your code harder to read and maintain
  2. After Unwrapping with Guard or If let you recieve absolutely No debuging information.

Unwrap Solves these problems by providing Syntactical Sugar to your code.
Quickly and easy unwrap your optionals with .unwrap and provide debug information such as which line and file the crash happened with .unwrap(debug:)

Usage

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]

Descriptive Debug Messages

screen shot 2017-12-19 at 17 35 03

Another Real-World Example

Without Using Unwrap

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)
    }

}

With Unwrap

class LoginController: UIViewController {
    var token: Token?
    override func viewDidLoad() {
        super.viewDidLoad()
        LoginService.login(token.unwrap())
    }
}

Start Shreadding lines of code

screen shot 2017-12-20 at 12 57 13

Clean, Succinct, and with more descriptive crashes!

screen shot 2017-12-20 at 13 03 52

Installing

  • For iOS 8+ projects with CocoaPods:
    pod 'Sukari'

    Deployment

just clone the repo and run on Xcode

Contributing

Please read CONTRIBUTING.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 file for details

Latest podspec

{
    "name": "Sukari",
    "version": "0.2.1",
    "summary": "Elegant Syntactic Sugar For Swift",
    "description": "Sukari ud83cudf6f is a thin light weight framweork  that provides you with Elegant Syntactic Sugar For Swift which will:n1.clean up your codebase and make it easier to read ud83dudcd6n2.Easily Intialize objects ud83dudee0n3.Throw away Guard Statements with Unwrap ud83cudfab",
    "homepage": "https://github.com/chrisbkarani/Sukari",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Chris Karani": "[email protected]"
    },
    "social_media_url": "https://twitter.com/cbkarani",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9",
        "watchos": "2.0",
        "tvos": "9.0"
    },
    "source": {
        "git": "https://github.com/chrisbkarani/Sukari.git",
        "tag": "0.2.1"
    },
    "source_files": "Sources/*.swift",
    "frameworks": [
        "Foundation",
        "CoreGraphics"
    ]
}

Pin It on Pinterest

Share This