Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b53d401d3 | |||
| d5d08bf252 | |||
| 8b5145090c | |||
| 9cf41812fc | |||
| 44d4efd4d5 | |||
| 3280ff38a3 | |||
| 2d0a9baeec | |||
| f2b0035d85 | |||
| 411f0dc5e3 | |||
| 993d460688 | |||
| d6d38f69eb |
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
Pod::Spec.new do |s|
|
||||
s.name = 'PluggableApplicationDelegate'
|
||||
s.version = '0.1.0'
|
||||
s.version = '0.1.2'
|
||||
s.summary = 'Services oriented AppDelegate in Swift 3.'
|
||||
s.description = <<-DESC
|
||||
PluggableApplicationDelegate is a way of decoupling AppDelegate, by splitting it into small modules called ApplicationService.
|
||||
|
||||
@@ -18,13 +18,9 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
|
||||
public var window: UIWindow?
|
||||
|
||||
open var services: [ApplicationService] { return [] }
|
||||
private var _services: [ApplicationService]?
|
||||
public var __services: [ApplicationService] {
|
||||
if _services == nil {
|
||||
_services = services
|
||||
}
|
||||
return _services!
|
||||
}
|
||||
private lazy var __services: [ApplicationService]! = {
|
||||
return self.services
|
||||
}()
|
||||
|
||||
@available(iOS 2.0, *)
|
||||
public func applicationDidFinishLaunching(_ application: UIApplication) {
|
||||
@@ -36,23 +32,27 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
@available(iOS 6.0, *)
|
||||
public func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
|
||||
var result = true
|
||||
|
||||
for service in __services {
|
||||
if let serviceResult = service.application?(application, willFinishLaunchingWithOptions: launchOptions) {
|
||||
if serviceResult == false {
|
||||
return false
|
||||
result = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
return result
|
||||
}
|
||||
|
||||
@available(iOS 3.0, *)
|
||||
public func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool {
|
||||
var result = true
|
||||
|
||||
for service in __services {
|
||||
if let serviceResult = service.application?(application, didFinishLaunchingWithOptions: launchOptions) {
|
||||
if serviceResult == false {
|
||||
return false
|
||||
result = false
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,9 +77,11 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
@available(iOS, introduced: 2.0, deprecated: 9.0, message: "Please use application:openURL:options:")
|
||||
public func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
|
||||
var result = true
|
||||
|
||||
for service in __services {
|
||||
if service.application?(application, handleOpen: url) == false {
|
||||
return false
|
||||
result = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,9 +90,11 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
@available(iOS, introduced: 4.2, deprecated: 9.0, message: "Please use application:openURL:options:")
|
||||
public func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
|
||||
var result = true
|
||||
|
||||
for service in __services {
|
||||
if service.application?(application, open: url, sourceApplication: sourceApplication, annotation: annotation) == false {
|
||||
return false
|
||||
result = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,13 +103,15 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
@available(iOS 9.0, *)
|
||||
public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
|
||||
var result = true
|
||||
|
||||
for service in __services {
|
||||
if service.application?(app, open: url, options: options) == false {
|
||||
return false
|
||||
result = false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
return result
|
||||
}
|
||||
|
||||
@available(iOS 2.0, *)
|
||||
@@ -158,7 +164,7 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
|
||||
// This callback will be made upon calling -[UIApplication registerUserNotificationSettings:]. The settings the user has granted to the application will be passed in as the second argument.
|
||||
@available(iOS 8.0, *)
|
||||
@available(iOS, introduced: 8.0, deprecated: 10.0, message: "Use UserNotification UNNotification Settings instead")
|
||||
public func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
|
||||
for service in __services {
|
||||
service.application?(application, didRegister: notificationSettings)
|
||||
@@ -332,13 +338,15 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
|
||||
// If unimplemented, the default behavior is to allow the extension point identifier.
|
||||
@available(iOS 8.0, *)
|
||||
public func application(_ application: UIApplication, shouldAllowExtensionPointIdentifier extensionPointIdentifier: UIApplicationExtensionPointIdentifier) -> Bool {
|
||||
var result = true
|
||||
|
||||
for service in __services {
|
||||
if service.application?(application, shouldAllowExtensionPointIdentifier: extensionPointIdentifier) == false {
|
||||
return false
|
||||
result = false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -355,24 +363,28 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
|
||||
|
||||
@available(iOS 6.0, *)
|
||||
public func application(_ application: UIApplication, shouldSaveApplicationState coder: NSCoder) -> Bool {
|
||||
var result = false
|
||||
|
||||
for service in __services {
|
||||
if service.application?(application, shouldSaveApplicationState: coder) == true {
|
||||
return true
|
||||
result = true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return result
|
||||
}
|
||||
|
||||
@available(iOS 6.0, *)
|
||||
public func application(_ application: UIApplication, shouldRestoreApplicationState coder: NSCoder) -> Bool {
|
||||
var result = false
|
||||
|
||||
for service in __services {
|
||||
if service.application?(application, shouldRestoreApplicationState: coder) == true {
|
||||
return true
|
||||
result = true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return result
|
||||
}
|
||||
|
||||
@available(iOS 6.0, *)
|
||||
@@ -396,13 +408,15 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
|
||||
// or application:didFailToContinueUserActivityWithType:error: if an error was encountered.
|
||||
@available(iOS 8.0, *)
|
||||
public func application(_ application: UIApplication, willContinueUserActivityWithType userActivityType: String) -> Bool {
|
||||
var result = false
|
||||
|
||||
for service in __services {
|
||||
if service.application?(application, willContinueUserActivityWithType: userActivityType) == true {
|
||||
return true
|
||||
result = true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -412,13 +426,15 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
|
||||
// restoreUserActivityState on all objects.
|
||||
@available(iOS 8.0, *)
|
||||
public func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Swift.Void) -> Bool {
|
||||
var result = false
|
||||
|
||||
for service in __services {
|
||||
if service.application?(application, continue: userActivity, restorationHandler: restorationHandler) == true {
|
||||
return true
|
||||
result = false
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -428,8 +444,6 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
|
||||
for service in __services {
|
||||
service.application?(application, didFailToContinueUserActivityWithType: userActivityType, error: error)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -439,8 +453,6 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
|
||||
for service in __services {
|
||||
service.application?(application, didUpdate: userActivity)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -452,7 +464,5 @@ open class PluggableApplicationDelegate: UIResponder, UIApplicationDelegate {
|
||||
for service in __services {
|
||||
service.application?(application, userDidAcceptCloudKitShareWith: cloudKitShareMetadata)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
[](http://cocoapods.org/pods/PluggableApplicationDelegate)
|
||||
|
||||
## Introduction
|
||||
`AppDelegate` is a traditional example of bad code. Lots of line codes 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.
|
||||
`AppDelegate` is a traditional example of bad code. Lots of line 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 `PluggableApplicationDelegate` you decouple AppDelegate from the services that you plug to it. Each `ApplicationService` has its own life cycle that is shared with `AppDelegate`.
|
||||
|
||||
## At a glance
|
||||
@@ -54,7 +54,7 @@ Yes. That's all. Simple.
|
||||
|
||||
## How does this work?
|
||||
|
||||
You may want to read my Medium post about Pluggable App Delegate.
|
||||
You may want to read my [Medium post about Pluggable App Delegate](https://medium.com/ios-os-x-development/pluggableapplicationdelegate-e50b2c5d97dd#.sz50l4d0l).
|
||||
Basically, you do an inversion of control. Instead of let AppDelegate instantiate your dependencies, perform actions at every step of its life cycle, you create objects that share the AppDelegate life cycle and plug them into your AppDelegate.
|
||||
Those objects are observers of the AppDelegate. Your AppDelegate has the only responsibility of notify them about its life cycle events.
|
||||
|
||||
@@ -64,13 +64,15 @@ To run the example project, clone the repo, and run `pod install` from the Examp
|
||||
|
||||
## Requirements
|
||||
|
||||
PluggableApplicationDelegate requires Swift 3.0 or above.
|
||||
|
||||
## Installation
|
||||
|
||||
PluggableApplicationDelegate is available through [CocoaPods](http://cocoapods.org). To install
|
||||
it, simply add the following line to your Podfile:
|
||||
|
||||
```ruby
|
||||
pod "PluggableApplicationDelegate"
|
||||
pod "PluggableApplicationDelegate", :git => "https://github.com/fmo91/PluggableApplicationDelegate"
|
||||
```
|
||||
|
||||
## Author
|
||||
|
||||
Reference in New Issue
Block a user