Latest 0.9.2
License MIT
Platforms ios 8.0, requires ARC

CocoaPods Status
Build Status

Framework grouping my utilities to use in various projects


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

pod "Swiftility"


import Swiftility


Checkout the MVVM implementation example I wrote using Swiftility

Type safe UIKit


/// Define Storyboard convertible type

enum Storyboards: String, StoryboardConvertible {
    case Main, Settings, Explore

    var storyboardName: String {
        return self.rawValue

/// Define your view controller built in the `Settings` storyboard
// "SettingsViewController" should be the identifier in the storyboard (same as class name)

class SettingsViewController: UIViewController, FromStoryboard {
    static let ownStoryboard: StoryboardConvertible = Storyboards.Settings

/// Now you can do this

let settingsVC = SettingsViewController.instantiateFromStoryboard()


// "SettingsViewController.xib" should be the file containing SettingsViewController

class SettingsViewController: UIViewController, FromNib { ... }

// "MyView.xib" should be the file containing MyView

class MyView: UIView, FromNib { ... }

/// Now you can do this

let settingsVC = SettingsViewController.instantiateFromNib()

let myView = MyView.instantiateFromNib()


/// Define cell defined in "MyCell.xib"

class MyCell: UITableViewCell, FromNib { ... }

// Register cell


/// Later

let cell: MyCell = tableView.dequeueReusableCell(MyCell)


/// Define cell defined in "MyCell.xib"

class MyCell: UICollectionViewCell, FromNib { ... }


/// Define custom view defined in "MyCustomView.xib"

class MyCustomView: UICollectionReusableView, FromNib { ... }

collectionView.registerSupplementaryView(MyCustomView.self, forSupplementaryViewOfKind: UICollectionElementKindSectionHeader)

/// Later

let supView: MyCustomView = collectioView.dequeueReusableSupplementaryView(kind: UICollectionElementKindSectionHeader, forIndexPath: someIndexPath)

let cell: MyCell = collectioView.dequeueReusableCell(MyCell.self, forIndexPath: someIndexPath)


Lightweight binding in Swift

struct Dynamic<T> {
    var value: T

    // ...

    init(_ value: T)

    // ...

    func bind(listener: T -> Void)

    // ...

/// Usage example

var email: Dynamic<String>("")

email.bind { value in
    print("Email is now: (value)")

email.value = "[email protected]"
// prints "Email is now: [email protected]"

Grand Central Dispatch

Convenience use of GCD queues

enum GCDQueue {
    case Main
    case High
    case Default
    case Low
    case Background
    case Custom(dispatch_queue_t)


func async(queue: GCDQueue = .Default, closure: dispatch_block_t)
func async_main(closure: dispatch_block_t) // same as calling async(.Main, closure: closure)

async {
    // Asynchronous code

    async_main {
        // Main thread code


func after(delay: Double, queue: GCDQueue = .Main, closure: dispatch_block_t)
func delay(delay: Double, queue: GCDQueue = .Main, closure: dispatch_block_t) // Same as above

after(2.5) {
    // Executed after 2.5 seconds


Container of weak variable

struct Weak<T: AnyObject> {
    weak var value : T?

    init (_ value: T)

/// Usage example

let arrayOfViewControllers = [Weak(vc1), Weak(vc2), Weak(vc3)]
let vc1View = arrayOfViewControllers[0].value?.view

Weak Timer

class WeakTimer {
    static func scheduledTimerWithTimeInterval(timeInterval: NSTimeInterval, userInfo: AnyObject? = nil, repeats: Bool = false, callback: () -> Void) -> NSTimer

// Usage example

WeakTimer.scheduledTimerWithTimeInterval(1, repeats: true) { [weak self] in
    // Code repeated every 1 second
    // Do something with weak self?


Allan Barbato, [email protected]


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

Latest podspec

    "name": "Swiftility",
    "version": "0.9.2",
    "summary": "allbto utility library to use across my projects.",
    "homepage": "",
    "license": {
        "type": "MIT"
    "authors": "Allan Bto",
    "platforms": {
        "ios": "8.0"
    "source": {
        "git": "",
        "tag": "0.9.2"
    "public_header_files": "Swiftility/**/*.h",
    "source_files": "Swiftility/Sources/**/*.{h,m,swift}",
    "requires_arc": true

Pin It on Pinterest

Share This