Git Product home page Git Product logo

gaine's Introduction

Gaine

CI Status Version License Platform

What is Gaine

Gaine is a tiny and elegant Swift Framework for initialize value and object conveniently.By the way, this repo is inspire by Then.

Why Gaine

There is comparison between Gaine way and Then way:

1. Create UIButton

Then way

lazy var foo = UILabel().then {
   $0.textAlignment = .center
   $0.textColor = .black
   $0.text = "Hello, World!"
}

Gaine way

lazy var foo = Gaine(UILabel()) {
   $0.textAlignment = .center
   $0.textColor = .black
   $0.text = "Hello, World!"
}

2. Create Custom Type

Then way

class MyType {
    var name: String?
}

/// we need to write this line to make custom type confirm `Then` protocol
extension MyType: Then {}

class Demo {

    lazy var foo = MyType().then {
        $0.name = "value"
    }
}

Gaine way

class MyType {
    var name: String?
}

/// we don't need to write any more code for custom type
class Demo {

    lazy var foo = Gaine(MyType()) {
        $0.name = "value"
    }
}

3. Deal with value Type

Then way

class Demo {

    /// we need to use another keyword `with`
    lazy var foo = CGSize().with {
        $0.width = 100
        $0.height = 200
    }
}

Gaine way

class Demo {

    /// the way to initialize is same
    lazy var foo = Gaine(CGSize()) {
       $0.width = 100
       $0.height = 200
    }
}

4. Less Code

All code for Gaine is just 5 lines.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Installation

Gaine is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'Gaine'

Author

Maru-zhang, [email protected]

License

Gaine is available under the MIT license. See the LICENSE file for more info.

gaine's People

Contributors

maru-zhang avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

carabina

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.