TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Sep 2016 |
SPMSupports SPM | ✗ |
Maintained by Igor Matyushkin.
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.
Sirius
folder to your project.or
Sirius
cocoapodNote: For Swift 2.x use Sirius v1.0
. For Swift 3.0 use Sirius v3.0
.
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.
let classNameIncludingNamespace = SomeClass.className(includeNamespace: true) // "com.domain.appName.SomeClass"
let classNameWithoutNamespace = SomeClass.className(includeNamespace: false) // "SomeClass"
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
})
}
Sirius
is available under the MIT license. See the LICENSE
file for more info.