10 Commits

Author SHA1 Message Date
Fernando Ortiz d5d08bf252 Bugfixing 2017-04-02 18:35:25 -03:00
Fernando Martín Ortiz 8b5145090c Merge pull request #5 from SimonFairbairn/DeprecationWarning
Fixes issue #2
2017-03-30 16:30:36 -03:00
Simon Fairbairn 9cf41812fc Fixes deprecation warning when building for iOS 10 2017-03-30 11:17:12 +02:00
Fernando Martín Ortiz 44d4efd4d5 Update README.md 2017-03-19 10:35:22 -03:00
Fernando Martín Ortiz 3280ff38a3 Merge pull request #1 from MariuszWisniewski/patch-1
Change Obj-C style lazy into new new Swift-style lazy
2017-03-10 10:18:35 -03:00
Mariusz Wisniewski 2d0a9baeec True lazy variable
Change __services and _services into just one lazy variable
2017-03-10 14:15:03 +01:00
Fernando Martín Ortiz f2b0035d85 Update README.md 2017-02-27 09:03:15 -08:00
Fernando Ortiz 411f0dc5e3 Merge branch 'master' of https://github.com/fmo91/PluggableApplicationDelegate 2017-02-26 22:01:21 -03:00
Fernando Martín Ortiz 993d460688 Update README.md 2017-02-26 21:55:59 -03:00
Fernando Martín Ortiz d6d38f69eb Update README.md 2017-02-26 21:54:34 -03:00
4 changed files with 54 additions and 35 deletions
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Workspace
version = "1.0">
<FileRef
location = "self:">
</FileRef>
</Workspace>
+1 -1
View File
@@ -8,7 +8,7 @@
Pod::Spec.new do |s|
s.name = 'PluggableApplicationDelegate'
s.version = '0.1.0'
s.version = '0.1.1'
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
return result
}
}
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
}
}
+5 -3
View File
@@ -6,7 +6,7 @@
[![Platform](https://img.shields.io/cocoapods/p/PluggableApplicationDelegate.svg?style=flat)](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