Latest 0.3.1
Homepage https://github.com/Wisors/RunIt
License MIT
Platforms ios 8.0
Authors

Swift 2.2 compatible
CocoaPods compatible
Platform iOSLicense: MIT

RunIt is a super lightweight yet powerful system components manager. It helps to clean your code from unesessary singletons usage. RunIt has an easy to go interface and provides you an opportunity to extend it for your personal needs.

Features

  • [x] Thread-safe access for your components
  • [x] Generic getters
  • [x] Extensibility
  • [x] Remove components only by it type
  • [x] NSOperation support (see NSOperation support)
  • [ ] Remove components by component object itself

Getting Started

An example app is included demonstrating RunIt’s functionality.

Basic usage

As example, suppose you have an application that uses user location and handles push notifcation. You know that both components available only if user grant access to it. So, no need to lauch and store your location service in singleton if it unavailable.

// Somewhere in app initialization proccess
if locationIsAvailable {

    let locationService = LocationComponent()
    RunIt.add(locationService)
}
if APNSIsAvailable {

    let APNSService = APNSComponent()
    RunIt.add(APNSService)
    // or
    RunIt.add(component: APNSService, forKey: "APNSService")
}

Later, anywhere in your code you have access to your components with generic getters.

let apnsService: LocationComponent? = RunIt.get()
let apnsService: APNSComponent? = RunIt.get(componentForKey: "APNSService")

No need for component anymore? Easy

RunIt.remove(component: component)
RunIt.remove(componentForKey: "APNSService")

All provided actions on RunIt are thread-safe.

Run your components

Your component may conforms to protocol Runnable and RunIt will automaticaly runs and stops your component on add and remove operations. Furthermore, run will be executed on separate queue (background by default). You can control this behavior through flags and by customization of runOperationQueue:

RunIt.runComponentsOnAdd = false
RunIt.stopComponentOnRemove = false
RunIt.syncQueue = dispatch_get_main_queue() //Make your compoents run in main thread
RunIt.runOperationQueue.maxConcurrentOperationCount = 2

It’s easy to control component’s run queue or it priority, just create a custom queue in your component:

class SomeComponent: Runnable {

    private(set) public var isRunning: Bool
    public var runQueue: dispatch_queue_t? = dispatch_queue_create("YourQueue", DISPATCH_QUEUE_CONCURRENT)
    public var priority: NSOperationQueuePriority = .High

    ...
}

NSOperation support

You are always welcome to add custom NSOperation(s) to RunIt.runOperationQueue, but you have to be aware that these operations will not cannibalize a run progress of your components. So, in case of large amount of NSOperation objects it’s wise to add them with lower priority than your components used.

Installation

CocoaPods

To integrate RunIt into your Xcode project using CocoaPods, specify it in your Podfile:

pod 'RunIt'

Manual

Clone the repo and drag files from Sources folder into your Xcode project.

Requirements

  • Swift 3.0
  • iOS 8.0+
  • Xcode 7.0+

License

RunIt is available under the MIT license. See LICENSE for details.

Latest podspec

{
    "name": "RunIt",
    "module_name": "RunIt",
    "version": "0.3.1",
    "homepage": "https://github.com/Wisors/RunIt",
    "summary": "A simple component helps you have only one Singleton.",
    "authors": {
        "Nikishin Alexander": "[email protected]"
    },
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "Sources/*.swift",
    "source": {
        "git": "https://github.com/Wisors/RunIt.git",
        "tag": "0.3.1"
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This