Git Product home page Git Product logo

pluggableappdelegate's Introduction

PluggableAppDelegate

License Platform Cocoapods Compatible Carthage compatible

Twitter

A lightweight service-oriented ApplicationDelegate for iOS, made in Swift. Based on the Fernando MartΓ­n Ortiz's idea (his repo not supported now).

AppDelegate is a traditional example of bad code. Lots of lines of code that makes so much different things are put together in methods that are called within the application life cycle. But all of those concerns are over.

Using PluggableAppDelegate you separate AppDelegate from the services that you can plug to it. Each ApplicationService has its own life cycle that is shared with AppDelegate.

Requirements

  • iOS 9.0+
  • Xcode 10.2+
  • Swift 5.0

Usage

Here is how a ApplicationService is like:

import Foundation

import PluggableAppDelegate

final class LoggerApplicationService: NSObject, ApplicationService {

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
        print("πŸŽ‰ LoggerApplicationService has started!")
        return true
    }

    func applicationDidEnterBackground(_ application: UIApplication) {
        print("πŸ™€ LoggerApplicationService has entered background")
    }

    func applicationWillEnterForeground(_ application: UIApplication) {
        print("😻 LoggerApplicationService has entered foreground")
    }
}

That's all. It is exactly the same as a AppDelegate. Think of ApplicationService as sub-AppDelegates.

In AppDelegate you just have to inherit from PluggableApplicationDelegate to register the services.

import UIKit

import PluggableAppDelegate

@UIApplicationMain
class AppDelegate: PluggableApplicationDelegate {

    override var services: [ApplicationService] {
        return [
            RootVCApplicationService(),
            LoggerApplicationService()
        ]
    }
}

Installation

CocoaPods

You can use CocoaPods.

platform :ios, '9.0'
use_frameworks!

target 'MyApp' do
  pod 'PluggableAppDelegate'
end

Carthage

You can use Carthage. Specify in Cartfile:

github "pchelnikov/PluggableAppDelegate"

Run carthage to build the framework and drag the built MarkerKit.framework into your Xcode project. Follow build instructions.

Contribution

Author

Michael Pchelnikov

You can follow me on Twitter at @pchelnikov

Credits

Fernando MartΓ­n Ortiz

License

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

pluggableappdelegate's People

Contributors

pchelnikov avatar kirill-kovalev avatar kagenzhao avatar damarte avatar megal avatar

Watchers

Illarionov Oleg avatar Simon V. avatar

Forkers

checkyou

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.