Latest 3.0
Homepage https://github.com/igormatyushkin014/Sirius
License MIT
Platforms ios 9.0
Authors

Sirius




At a Glance

Swift is still a brand new language, which, very often, does not relieve the developer from writing a lot of boilerplate code. The main goal of Sirius framework is to simplify work with fundamental things in modern programming: the objects. Framework includes set of extensions for Swift’s native types and protocols, which makes programming easier and allows to save many lines of code.

How To Get Started

  • Copy content of Sirius folder to your project.

or

  • Use Sirius cocoapod

Requirements

  • iOS 9.0 and later
  • Xcode 8 and later

Note: For Swift 2.x use Sirius v1.0. For Swift 3.0 use Sirius v3.0.

Usage

Manipulation with objects

let object = SomeClass()

object.use { (object) in
    // Do several operations with object...
}

object.useAs(NSString.self) { (object) in
    // Do something with object casted to NSString type...
}

Both methods use and useAs support chain calls, so it’s possible to write something like this:

object.use { (object) in
    // Do several operations with object...
}.useAs(NSString.self) { (object) in
    // Do something with object casted to NSString type...
}.useAs(NSNumber.self) { (object) in
    // Do something with object casted to NSNumber type...
}

Since two methods above return receiver’s instance, you can use them with initializer like this:

let view = UIView().use { (object) in
    object --> .blueColor()
    object.clipsToBounds = true
}

This approach makes code more demonstrative and clear.

Class name

let classNameIncludingNamespace = SomeClass.className(includeNamespace: true) // "com.domain.appName.SomeClass"
let classNameWithoutNamespace = SomeClass.className(includeNamespace: false) // "SomeClass"

Real-life examples

Usually, when you want to set up view’s layer, for example – make corners rounded, you write a code like this:

view.layer.backgroundColor = UIColor.whiteColor().CGColor
view.layer.borderColor = UIColor.blackColor().CGColor
view.layer.borderWidth = 1.0
view.layer.cornerRadius = view.bounds.size.width / 2.0
view.layer.masksToBounds = true

With Sirius you can forget about view. input on each line:

view.layer.use { (layer) in
    layer.backgroundColor = UIColor.whiteColor().CGColor
    layer.borderColor = UIColor.blackColor().CGColor
    layer.borderWidth = 1.0
    layer.cornerRadius = view.bounds.size.width / 2.0
    layer.masksToBounds = true
}

The same you can do on initialization of the view:

let view = UIView().use { (view) in
    view.frame = CGRect(x: 0.0, y: 0.0, width: 200.0, height: 200.0)

    view.layer.use({ (layer) in
        layer.backgroundColor = UIColor.whiteColor().CGColor
        layer.borderColor = UIColor.blackColor().CGColor
        layer.borderWidth = 1.0
        layer.cornerRadius = view.bounds.size.width / 2.0
        layer.masksToBounds = true
    })
}

License

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

Latest podspec

{
    "name": "Sirius",
    "version": "3.0",
    "summary": "View at Swift from another world.",
    "description": "`Sirius` framework simplifies the fundamental things in modern programming: objects. Framework includes set of extensions for Swift's native types and protocols, which makes programming easier and allows to save many lines of code.",
    "homepage": "https://github.com/igormatyushkin014/Sirius",
    "screenshots": "https://github.com/igormatyushkin014/Sirius/raw/master/Logo/logo-1024-300.png",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Igor Matyushkin": "[email protected]"
    },
    "social_media_url": "http://twitter.com/igormatyushkin1",
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/igormatyushkin014/Sirius.git",
        "tag": "3.0"
    },
    "source_files": [
        "Sirius",
        "Sirius/**/*"
    ]
}

Pin It on Pinterest

Share This