CocoaPods trunk is moving to be read-only. Read more on the blog, there are 14 months to go.
| TestsTested | ✗ |
| LangLanguage | SwiftSwift |
| License | MIT |
| ReleasedLast Release | Jan 2016 |
| SPMSupports SPM | ✗ |
Maintained by Khoa Pham.
Lighter AppDelegate by dispatching events
To run the example project, clone the repo, and run pod install from the Example directory first.
UIApplicationDelegate events into specific Service class. We can have RootService, DebugService, AnalyticsService, ...class RootService : NSObject, UIApplicationDelegate {
func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
appDelegate().window = UIWindow(frame: UIScreen.mainScreen().bounds)
showHome()
appDelegate().window?.makeKeyAndVisible()
return true
}
}
extension RootService {
func showHome() {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
appDelegate().window?.rootViewController = storyboard.instantiateInitialViewController()
}
}
extension RootService {
func appDelegate() -> AppDelegate {
return UIApplication.sharedApplication().delegate as! AppDelegate
}
}Dispatcher with your list of servicesUIApplicationDelegate events to Dispatcher
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let dispatcher = Dispatcher(services: [RootService()])
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
return dispatcher.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}LighterAppDelegate
dispatcher()
LighterAppDelegate has protocol extension with default implementations for App State Changes and URL events, which is suitable for common usage.Dispatcher
@UIApplicationMain
class AppDelegate: UIResponder, LighterAppDelegate {
var window: UIWindow?
let simpleDispatcher = Dispatcher(services: [RootService()])
func dispatcher() -> Dispatcher {
return simpleDispatcher
}
func applicationDidReceiveMemoryWarning(application: UIApplication) {
dispatcher().applicationDidReceiveMemoryWarning(application)
}
}UIApplicationDelegate functions in case you truly need. Unnecessary functions can cause problemsYou've implemented -[ application:performFetchWithCompletionHandler:], but you still need to add "fetch" to the list of your supported UIBackgroundModes in your Info.plist.
You've implemented -[ application:didReceiveRemoteNotification:fetchCompletionHandler:], but you still need to add "remote-notification" to the list of your supported UIBackgroundModes in your Info.plist.
remoteNotification events also consider your app to support Push Notification
Your app appears to include API used to register with the Apple Push Notification service, but the app signature's entitlements do not include the "aps-environment" entitlement
UIApplicationDelegate functions inside your AppDelegate. This is not a problem with LighterAppDelegate since functions are implemented in its protocol extension !!LighterAppDelegate is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "LighterAppDelegate"Credit goes to http://sizeof.io/service-oriented-appdelegate/
Khoa Pham, [email protected]
LighterAppDelegate is available under the MIT license. See the LICENSE file for more info.