├── .gitignore
├── .swiftpm
└── xcode
│ └── package.xcworkspace
│ └── contents.xcworkspacedata
├── LICENSE
├── Package.swift
├── README.md
├── Sample
├── AppDelegate.swift
├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
├── Info.plist
├── LoginService.swift
├── Person.swift
└── ViewController.swift
├── SwiftEventBus.podspec
├── SwiftEventBus.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
└── xcshareddata
│ └── xcschemes
│ └── SwiftEventBus.xcscheme
└── SwiftEventBus
├── Info.plist
├── SwiftEventBus.h
└── SwiftEventBus.swift
/.gitignore:
--------------------------------------------------------------------------------
1 | # Xcode
2 | #
3 | build/
4 | *.pbxuser
5 | !default.pbxuser
6 | *.mode1v3
7 | !default.mode1v3
8 | *.mode2v3
9 | !default.mode2v3
10 | *.perspectivev3
11 | !default.perspectivev3
12 | xcuserdata
13 | *.xccheckout
14 | *.moved-aside
15 | DerivedData
16 | *.hmap
17 | *.ipa
18 | *.xcuserstate
19 | .idea/
20 | # CocoaPods
21 | #
22 | # We recommend against adding the Pods directory to your .gitignore. However
23 | # you should judge for yourself, the pros and cons are mentioned at:
24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
25 | #
26 | # Pods/
27 | .swiftpm
28 |
--------------------------------------------------------------------------------
/.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 César Ferreira
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/Package.swift:
--------------------------------------------------------------------------------
1 | // swift-tools-version:5.3
2 |
3 | import PackageDescription
4 |
5 | let package = Package(
6 | name: "SwiftEventBus",
7 | platforms: [
8 | .macOS(.v10_10),
9 | .iOS(.v10)
10 | ],
11 |
12 | products: [.library(
13 | name: "SwiftEventBus",
14 | targets: ["SwiftEventBus"])
15 | ],
16 |
17 | targets: [.target(
18 | name: "SwiftEventBus",
19 | path: "SwiftEventBus",
20 | exclude: [
21 | "Info.plist",
22 | ])
23 | ],
24 |
25 | swiftLanguageVersions: [.v5]
26 | )
27 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SwiftEventBus
2 | [](http://cocoapods.org/pods/SwiftEventBus)
3 | [](http://cocoapods.org/pods/SwiftEventBus)
4 | [](http://cocoapods.org/pods/SwiftEventBus)
5 | [](http://cocoapods.org/pods/SwiftEventBus)
6 |
7 | Allows publish-subscribe-style communication between components without requiring the components to explicitly be aware of each other
8 |
9 | ## Features
10 |
11 | - [x] simplifies the communication between components
12 | - [x] decouples event senders and receivers
13 | - [x] avoids complex and error-prone dependencies and life cycle issues
14 | - [x] makes your code simpler
15 | - [x] is fast
16 | - [x] is tiny
17 | - [x] Thread-safe
18 |
19 | ## Installation
20 |
21 | ### Cocoapods
22 |
23 | ```bash
24 | pod 'SwiftEventBus', :tag => '5.1.0', :git => 'https://github.com/cesarferreira/SwiftEventBus.git'
25 | ```
26 |
27 | ### Carthage
28 | ```bash
29 | github "cesarferreira/SwiftEventBus" == 5.1.0
30 | ```
31 |
32 | ### Versions
33 |
34 | - `5.+` for `swift 5`
35 | - `3.+` for `swift 4.2`
36 | - `2.+` for `swift 3`
37 | - `1.1.0` for `swift 2.2`
38 |
39 | ## Usage
40 | ### 1 - Prepare subscribers ###
41 |
42 | Subscribers implement event handling methods that will be called when an event is received.
43 |
44 | ```swift
45 | SwiftEventBus.onMainThread(target, name: "someEventName") { result in
46 | // UI thread
47 | }
48 |
49 | // or
50 |
51 | SwiftEventBus.onBackgroundThread(target, name:"someEventName") { result in
52 | // API Access
53 | }
54 | ```
55 |
56 | ### 2 - Post events ###
57 |
58 | Post an event from any part of your code. All subscribers matching the event type will receive it.
59 |
60 | ```swift
61 | SwiftEventBus.post("someEventName")
62 | ```
63 |
64 | --
65 |
66 | ### Eventbus with parameters
67 |
68 | Post event
69 |
70 | ```swift
71 | SwiftEventBus.post("personFetchEvent", sender: Person(name:"john doe"))
72 | ```
73 |
74 | Expecting parameters
75 | ```swift
76 | SwiftEventBus.onMainThread(target, name:"personFetchEvent") { result in
77 | let person : Person = result.object as Person
78 | println(person.name) // will output "john doe"
79 | }
80 | ```
81 |
82 | ### Posting events from the BackgroundThread to the MainThread
83 |
84 | Quoting the official Apple [documentation](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Notifications/Articles/Threading.html):
85 | > Regular notification centers deliver notifications on the thread in which the notification was posted
86 |
87 |
88 | Regarding this limitation, [@nunogoncalves](https://github.com/nunogoncalves) implemented the feature and provided a working example:
89 |
90 | ```swift
91 |
92 | @IBAction func clicked(sender: AnyObject) {
93 | count++
94 | SwiftEventBus.post("doStuffOnBackground")
95 | }
96 |
97 | @IBOutlet weak var textField: UITextField!
98 |
99 | var count = 0
100 |
101 | override func viewDidLoad() {
102 | super.viewDidLoad()
103 |
104 | SwiftEventBus.onBackgroundThread(self, name: "doStuffOnBackground") { notification in
105 | println("doing stuff in background thread")
106 | SwiftEventBus.postToMainThread("updateText")
107 | }
108 |
109 | SwiftEventBus.onMainThread(self, name: "updateText") { notification in
110 | self.textField.text = "\(self.count)"
111 | }
112 | }
113 |
114 | //Perhaps on viewDidDisappear depending on your needs
115 | override func viewWillDisappear(_ animated: Bool) {
116 | super.viewWillDisappear(animated)
117 |
118 | SwiftEventBus.unregister(self)
119 | }
120 | ```
121 | --
122 |
123 |
124 | ## Unregistering
125 |
126 | Remove all the observers from the target
127 | ```swift
128 | SwiftEventBus.unregister(target)
129 | ```
130 | Remove observers of the same name from the target
131 | ```swift
132 | SwiftEventBus.unregister(target, "someEventName")
133 | ```
134 |
--------------------------------------------------------------------------------
/Sample/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.swift
3 | // Sample
4 | //
5 | // Created by Cesar Ferreira on 17/09/2016.
6 | // Copyright © 2016 Cesar Ferreira. All rights reserved.
7 | //
8 |
9 | import UIKit
10 |
11 | @UIApplicationMain
12 | class AppDelegate: UIResponder, UIApplicationDelegate {
13 |
14 | var window: UIWindow?
15 |
16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
17 | // Override point for customization after application launch.
18 | self.subscribeToServices()
19 |
20 | return true
21 | }
22 |
23 | func subscribeToServices() {
24 | let _ = LoginService.init()
25 | // todo - rest of the services
26 | }
27 |
28 |
29 | }
30 |
31 |
--------------------------------------------------------------------------------
/Sample/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "scale" : "2x",
6 | "size" : "20x20"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "scale" : "3x",
11 | "size" : "20x20"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "scale" : "2x",
16 | "size" : "29x29"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "scale" : "3x",
21 | "size" : "29x29"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "scale" : "2x",
26 | "size" : "40x40"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "scale" : "3x",
31 | "size" : "40x40"
32 | },
33 | {
34 | "idiom" : "iphone",
35 | "scale" : "2x",
36 | "size" : "60x60"
37 | },
38 | {
39 | "idiom" : "iphone",
40 | "scale" : "3x",
41 | "size" : "60x60"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "scale" : "1x",
46 | "size" : "20x20"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "scale" : "2x",
51 | "size" : "20x20"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "scale" : "1x",
56 | "size" : "29x29"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "scale" : "2x",
61 | "size" : "29x29"
62 | },
63 | {
64 | "idiom" : "ipad",
65 | "scale" : "1x",
66 | "size" : "40x40"
67 | },
68 | {
69 | "idiom" : "ipad",
70 | "scale" : "2x",
71 | "size" : "40x40"
72 | },
73 | {
74 | "idiom" : "ipad",
75 | "scale" : "1x",
76 | "size" : "76x76"
77 | },
78 | {
79 | "idiom" : "ipad",
80 | "scale" : "2x",
81 | "size" : "76x76"
82 | },
83 | {
84 | "idiom" : "ipad",
85 | "scale" : "2x",
86 | "size" : "83.5x83.5"
87 | },
88 | {
89 | "idiom" : "ios-marketing",
90 | "scale" : "1x",
91 | "size" : "1024x1024"
92 | }
93 | ],
94 | "info" : {
95 | "author" : "xcode",
96 | "version" : 1
97 | }
98 | }
99 |
--------------------------------------------------------------------------------
/Sample/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/Sample/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
28 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
--------------------------------------------------------------------------------
/Sample/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIMainStoryboardFile
26 | Main
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/Sample/LoginService.swift:
--------------------------------------------------------------------------------
1 | //
2 | // GetDataService.swift
3 | // EventMyBus
4 | //
5 | // Created by César Ferreira on 06/02/15.
6 | // Copyright (c) 2015 linkedcare. All rights reserved.
7 | //
8 |
9 | import Foundation
10 | import SwiftEventBus
11 |
12 | class LoginService {
13 | init() {
14 |
15 | SwiftEventBus.onMainThread(self, name:"loginCall") { _ in
16 |
17 | print("Starting request...")
18 |
19 | var useless = 0
20 |
21 | for _ in 1...50000 {
22 | useless += 1
23 | }
24 |
25 | print("Request finished...")
26 |
27 | SwiftEventBus.post("login", sender: Person(name: "cesar ferreira"))
28 |
29 | }
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/Sample/Person.swift:
--------------------------------------------------------------------------------
1 | //
2 | // Person.swift
3 | // SwiftEventBus
4 | //
5 | // Created by César Ferreira on 09/02/15.
6 | // Copyright (c) 2015 cesarferreira. All rights reserved.
7 | //
8 |
9 | import Foundation
10 |
11 | class Person: NSObject {
12 | var name: String;
13 |
14 | init(name: String) {
15 | self.name = name;
16 | }
17 |
18 | }
19 |
--------------------------------------------------------------------------------
/Sample/ViewController.swift:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.swift
3 | // Sample
4 | //
5 | // Created by Cesar Ferreira on 17/09/2016.
6 | // Copyright © 2016 Cesar Ferreira. All rights reserved.
7 | //
8 |
9 | import UIKit
10 | import SwiftEventBus
11 |
12 | class ViewController: UIViewController {
13 |
14 | @IBOutlet weak var welcomeLabel: UILabel!
15 |
16 | override func viewDidLoad() {
17 | super.viewDidLoad()
18 |
19 | // Do any additional setup after loading the view, typically from a nib.
20 |
21 | SwiftEventBus.onMainThread(self, name: "login") { result in
22 |
23 | let p : Person = result?.object as! Person
24 |
25 | self.welcomeLabel.text = "Welcome \(p.name)"
26 |
27 | }
28 |
29 | SwiftEventBus.onMainThread(self, name: "loginFail") { _ in
30 | // handle herror on the UI thread
31 | print ("ERROR! Login failed");
32 | }
33 |
34 | }
35 |
36 |
37 | @IBAction func doClick(_ sender: AnyObject) {
38 | self.welcomeLabel.text = "Loading..."
39 |
40 | SwiftEventBus.post("loginCall")
41 | }
42 | }
43 |
44 |
--------------------------------------------------------------------------------
/SwiftEventBus.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = 'SwiftEventBus'
3 | s.version = '5.0.0'
4 | s.license = 'MIT'
5 | s.summary = 'Publish/subscribe event bus optimized for iOS'
6 | s.homepage = 'https://github.com/cesarferreira/SwiftEventBus'
7 | s.social_media_url = 'http://twitter.com/cesarmcferreira'
8 | s.authors = { 'César Ferreira' => 'cesar.manuel.ferreira@gmail.com' }
9 | s.source = { :git => 'https://github.com/cesarferreira/SwiftEventBus.git', :tag => s.version }
10 | s.ios.deployment_target = '9.0'
11 | s.osx.deployment_target = '10.10'
12 | s.source_files = 'SwiftEventBus/SwiftEventBus.swift'
13 | s.requires_arc = true
14 | end
15 |
--------------------------------------------------------------------------------
/SwiftEventBus.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 53;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | DBCE8D4F1D8DD5160012B477 /* SwiftEventBus.h in Headers */ = {isa = PBXBuildFile; fileRef = DBCE8D4D1D8DD5160012B477 /* SwiftEventBus.h */; settings = {ATTRIBUTES = (Public, ); }; };
11 | DBCE8D561D8DD63D0012B477 /* SwiftEventBus.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBCE8D551D8DD63D0012B477 /* SwiftEventBus.swift */; };
12 | DBCE8D5E1D8DD8890012B477 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBCE8D5D1D8DD8890012B477 /* AppDelegate.swift */; };
13 | DBCE8D601D8DD88A0012B477 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBCE8D5F1D8DD88A0012B477 /* ViewController.swift */; };
14 | DBCE8D631D8DD88A0012B477 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DBCE8D611D8DD88A0012B477 /* Main.storyboard */; };
15 | DBCE8D651D8DD88A0012B477 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DBCE8D641D8DD88A0012B477 /* Assets.xcassets */; };
16 | DBCE8D681D8DD88A0012B477 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DBCE8D661D8DD88A0012B477 /* LaunchScreen.storyboard */; };
17 | DBCE8D6F1D8DFAFA0012B477 /* LoginService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBCE8D6D1D8DFAFA0012B477 /* LoginService.swift */; };
18 | DBCE8D701D8DFAFA0012B477 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = DBCE8D6E1D8DFAFA0012B477 /* Person.swift */; };
19 | /* End PBXBuildFile section */
20 |
21 | /* Begin PBXFileReference section */
22 | DBCE8D4A1D8DD5160012B477 /* SwiftEventBus.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftEventBus.framework; sourceTree = BUILT_PRODUCTS_DIR; };
23 | DBCE8D4D1D8DD5160012B477 /* SwiftEventBus.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftEventBus.h; sourceTree = ""; };
24 | DBCE8D4E1D8DD5160012B477 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
25 | DBCE8D551D8DD63D0012B477 /* SwiftEventBus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftEventBus.swift; sourceTree = ""; };
26 | DBCE8D5B1D8DD8890012B477 /* Sample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Sample.app; sourceTree = BUILT_PRODUCTS_DIR; };
27 | DBCE8D5D1D8DD8890012B477 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
28 | DBCE8D5F1D8DD88A0012B477 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
29 | DBCE8D621D8DD88A0012B477 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
30 | DBCE8D641D8DD88A0012B477 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
31 | DBCE8D671D8DD88A0012B477 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
32 | DBCE8D691D8DD88A0012B477 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
33 | DBCE8D6D1D8DFAFA0012B477 /* LoginService.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginService.swift; sourceTree = ""; };
34 | DBCE8D6E1D8DFAFA0012B477 /* Person.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = ""; };
35 | /* End PBXFileReference section */
36 |
37 | /* Begin PBXFrameworksBuildPhase section */
38 | DBCE8D461D8DD5160012B477 /* Frameworks */ = {
39 | isa = PBXFrameworksBuildPhase;
40 | buildActionMask = 2147483647;
41 | files = (
42 | );
43 | runOnlyForDeploymentPostprocessing = 0;
44 | };
45 | DBCE8D581D8DD8890012B477 /* Frameworks */ = {
46 | isa = PBXFrameworksBuildPhase;
47 | buildActionMask = 2147483647;
48 | files = (
49 | );
50 | runOnlyForDeploymentPostprocessing = 0;
51 | };
52 | /* End PBXFrameworksBuildPhase section */
53 |
54 | /* Begin PBXGroup section */
55 | DBCE8D401D8DD5160012B477 = {
56 | isa = PBXGroup;
57 | children = (
58 | DBCE8D4C1D8DD5160012B477 /* SwiftEventBus */,
59 | DBCE8D5C1D8DD8890012B477 /* Sample */,
60 | DBCE8D4B1D8DD5160012B477 /* Products */,
61 | );
62 | sourceTree = "";
63 | };
64 | DBCE8D4B1D8DD5160012B477 /* Products */ = {
65 | isa = PBXGroup;
66 | children = (
67 | DBCE8D4A1D8DD5160012B477 /* SwiftEventBus.framework */,
68 | DBCE8D5B1D8DD8890012B477 /* Sample.app */,
69 | );
70 | name = Products;
71 | sourceTree = "";
72 | };
73 | DBCE8D4C1D8DD5160012B477 /* SwiftEventBus */ = {
74 | isa = PBXGroup;
75 | children = (
76 | DBCE8D551D8DD63D0012B477 /* SwiftEventBus.swift */,
77 | DBCE8D4D1D8DD5160012B477 /* SwiftEventBus.h */,
78 | DBCE8D4E1D8DD5160012B477 /* Info.plist */,
79 | );
80 | path = SwiftEventBus;
81 | sourceTree = "";
82 | };
83 | DBCE8D5C1D8DD8890012B477 /* Sample */ = {
84 | isa = PBXGroup;
85 | children = (
86 | DBCE8D6D1D8DFAFA0012B477 /* LoginService.swift */,
87 | DBCE8D6E1D8DFAFA0012B477 /* Person.swift */,
88 | DBCE8D5D1D8DD8890012B477 /* AppDelegate.swift */,
89 | DBCE8D5F1D8DD88A0012B477 /* ViewController.swift */,
90 | DBCE8D611D8DD88A0012B477 /* Main.storyboard */,
91 | DBCE8D641D8DD88A0012B477 /* Assets.xcassets */,
92 | DBCE8D661D8DD88A0012B477 /* LaunchScreen.storyboard */,
93 | DBCE8D691D8DD88A0012B477 /* Info.plist */,
94 | );
95 | path = Sample;
96 | sourceTree = "";
97 | };
98 | /* End PBXGroup section */
99 |
100 | /* Begin PBXHeadersBuildPhase section */
101 | DBCE8D471D8DD5160012B477 /* Headers */ = {
102 | isa = PBXHeadersBuildPhase;
103 | buildActionMask = 2147483647;
104 | files = (
105 | DBCE8D4F1D8DD5160012B477 /* SwiftEventBus.h in Headers */,
106 | );
107 | runOnlyForDeploymentPostprocessing = 0;
108 | };
109 | /* End PBXHeadersBuildPhase section */
110 |
111 | /* Begin PBXNativeTarget section */
112 | DBCE8D491D8DD5160012B477 /* SwiftEventBus */ = {
113 | isa = PBXNativeTarget;
114 | buildConfigurationList = DBCE8D521D8DD5160012B477 /* Build configuration list for PBXNativeTarget "SwiftEventBus" */;
115 | buildPhases = (
116 | DBCE8D451D8DD5160012B477 /* Sources */,
117 | DBCE8D461D8DD5160012B477 /* Frameworks */,
118 | DBCE8D471D8DD5160012B477 /* Headers */,
119 | DBCE8D481D8DD5160012B477 /* Resources */,
120 | );
121 | buildRules = (
122 | );
123 | dependencies = (
124 | );
125 | name = SwiftEventBus;
126 | productName = SwiftEventBus;
127 | productReference = DBCE8D4A1D8DD5160012B477 /* SwiftEventBus.framework */;
128 | productType = "com.apple.product-type.framework";
129 | };
130 | DBCE8D5A1D8DD8890012B477 /* Sample */ = {
131 | isa = PBXNativeTarget;
132 | buildConfigurationList = DBCE8D6A1D8DD88A0012B477 /* Build configuration list for PBXNativeTarget "Sample" */;
133 | buildPhases = (
134 | DBCE8D571D8DD8890012B477 /* Sources */,
135 | DBCE8D581D8DD8890012B477 /* Frameworks */,
136 | DBCE8D591D8DD8890012B477 /* Resources */,
137 | );
138 | buildRules = (
139 | );
140 | dependencies = (
141 | );
142 | name = Sample;
143 | productName = Sample;
144 | productReference = DBCE8D5B1D8DD8890012B477 /* Sample.app */;
145 | productType = "com.apple.product-type.application";
146 | };
147 | /* End PBXNativeTarget section */
148 |
149 | /* Begin PBXProject section */
150 | DBCE8D411D8DD5160012B477 /* Project object */ = {
151 | isa = PBXProject;
152 | attributes = {
153 | LastSwiftUpdateCheck = 0800;
154 | LastUpgradeCheck = 1240;
155 | ORGANIZATIONNAME = "Cesar Ferreira";
156 | TargetAttributes = {
157 | DBCE8D491D8DD5160012B477 = {
158 | CreatedOnToolsVersion = 8.0;
159 | DevelopmentTeam = 5549XPMRDN;
160 | LastSwiftMigration = 1020;
161 | ProvisioningStyle = Automatic;
162 | };
163 | DBCE8D5A1D8DD8890012B477 = {
164 | CreatedOnToolsVersion = 8.0;
165 | DevelopmentTeam = 5549XPMRDN;
166 | ProvisioningStyle = Automatic;
167 | };
168 | };
169 | };
170 | buildConfigurationList = DBCE8D441D8DD5160012B477 /* Build configuration list for PBXProject "SwiftEventBus" */;
171 | compatibilityVersion = "Xcode 11.4";
172 | developmentRegion = en;
173 | hasScannedForEncodings = 0;
174 | knownRegions = (
175 | en,
176 | Base,
177 | );
178 | mainGroup = DBCE8D401D8DD5160012B477;
179 | productRefGroup = DBCE8D4B1D8DD5160012B477 /* Products */;
180 | projectDirPath = "";
181 | projectRoot = "";
182 | targets = (
183 | DBCE8D491D8DD5160012B477 /* SwiftEventBus */,
184 | DBCE8D5A1D8DD8890012B477 /* Sample */,
185 | );
186 | };
187 | /* End PBXProject section */
188 |
189 | /* Begin PBXResourcesBuildPhase section */
190 | DBCE8D481D8DD5160012B477 /* Resources */ = {
191 | isa = PBXResourcesBuildPhase;
192 | buildActionMask = 2147483647;
193 | files = (
194 | );
195 | runOnlyForDeploymentPostprocessing = 0;
196 | };
197 | DBCE8D591D8DD8890012B477 /* Resources */ = {
198 | isa = PBXResourcesBuildPhase;
199 | buildActionMask = 2147483647;
200 | files = (
201 | DBCE8D681D8DD88A0012B477 /* LaunchScreen.storyboard in Resources */,
202 | DBCE8D651D8DD88A0012B477 /* Assets.xcassets in Resources */,
203 | DBCE8D631D8DD88A0012B477 /* Main.storyboard in Resources */,
204 | );
205 | runOnlyForDeploymentPostprocessing = 0;
206 | };
207 | /* End PBXResourcesBuildPhase section */
208 |
209 | /* Begin PBXSourcesBuildPhase section */
210 | DBCE8D451D8DD5160012B477 /* Sources */ = {
211 | isa = PBXSourcesBuildPhase;
212 | buildActionMask = 2147483647;
213 | files = (
214 | DBCE8D561D8DD63D0012B477 /* SwiftEventBus.swift in Sources */,
215 | );
216 | runOnlyForDeploymentPostprocessing = 0;
217 | };
218 | DBCE8D571D8DD8890012B477 /* Sources */ = {
219 | isa = PBXSourcesBuildPhase;
220 | buildActionMask = 2147483647;
221 | files = (
222 | DBCE8D601D8DD88A0012B477 /* ViewController.swift in Sources */,
223 | DBCE8D6F1D8DFAFA0012B477 /* LoginService.swift in Sources */,
224 | DBCE8D701D8DFAFA0012B477 /* Person.swift in Sources */,
225 | DBCE8D5E1D8DD8890012B477 /* AppDelegate.swift in Sources */,
226 | );
227 | runOnlyForDeploymentPostprocessing = 0;
228 | };
229 | /* End PBXSourcesBuildPhase section */
230 |
231 | /* Begin PBXVariantGroup section */
232 | DBCE8D611D8DD88A0012B477 /* Main.storyboard */ = {
233 | isa = PBXVariantGroup;
234 | children = (
235 | DBCE8D621D8DD88A0012B477 /* Base */,
236 | );
237 | name = Main.storyboard;
238 | sourceTree = "";
239 | };
240 | DBCE8D661D8DD88A0012B477 /* LaunchScreen.storyboard */ = {
241 | isa = PBXVariantGroup;
242 | children = (
243 | DBCE8D671D8DD88A0012B477 /* Base */,
244 | );
245 | name = LaunchScreen.storyboard;
246 | sourceTree = "";
247 | };
248 | /* End PBXVariantGroup section */
249 |
250 | /* Begin XCBuildConfiguration section */
251 | DBCE8D501D8DD5160012B477 /* Debug */ = {
252 | isa = XCBuildConfiguration;
253 | buildSettings = {
254 | ALWAYS_SEARCH_USER_PATHS = NO;
255 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
256 | CLANG_ANALYZER_NONNULL = YES;
257 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
258 | CLANG_CXX_LIBRARY = "libc++";
259 | CLANG_ENABLE_MODULES = YES;
260 | CLANG_ENABLE_OBJC_ARC = YES;
261 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
262 | CLANG_WARN_BOOL_CONVERSION = YES;
263 | CLANG_WARN_COMMA = YES;
264 | CLANG_WARN_CONSTANT_CONVERSION = YES;
265 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
266 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
267 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
268 | CLANG_WARN_EMPTY_BODY = YES;
269 | CLANG_WARN_ENUM_CONVERSION = YES;
270 | CLANG_WARN_INFINITE_RECURSION = YES;
271 | CLANG_WARN_INT_CONVERSION = YES;
272 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
273 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
274 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
275 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
276 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
277 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
278 | CLANG_WARN_STRICT_PROTOTYPES = YES;
279 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
280 | CLANG_WARN_SUSPICIOUS_MOVES = YES;
281 | CLANG_WARN_UNREACHABLE_CODE = YES;
282 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
283 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
284 | COPY_PHASE_STRIP = NO;
285 | CURRENT_PROJECT_VERSION = 1;
286 | DEBUG_INFORMATION_FORMAT = dwarf;
287 | ENABLE_STRICT_OBJC_MSGSEND = YES;
288 | ENABLE_TESTABILITY = YES;
289 | GCC_C_LANGUAGE_STANDARD = gnu99;
290 | GCC_DYNAMIC_NO_PIC = NO;
291 | GCC_NO_COMMON_BLOCKS = YES;
292 | GCC_OPTIMIZATION_LEVEL = 0;
293 | GCC_PREPROCESSOR_DEFINITIONS = (
294 | "DEBUG=1",
295 | "$(inherited)",
296 | );
297 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
298 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
299 | GCC_WARN_UNDECLARED_SELECTOR = YES;
300 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
301 | GCC_WARN_UNUSED_FUNCTION = YES;
302 | GCC_WARN_UNUSED_VARIABLE = YES;
303 | IPHONEOS_DEPLOYMENT_TARGET = 10.0;
304 | MTL_ENABLE_DEBUG_INFO = YES;
305 | ONLY_ACTIVE_ARCH = YES;
306 | SDKROOT = iphoneos;
307 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
308 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
309 | SWIFT_VERSION = 5.0;
310 | TARGETED_DEVICE_FAMILY = "1,2";
311 | VERSIONING_SYSTEM = "apple-generic";
312 | VERSION_INFO_PREFIX = "";
313 | };
314 | name = Debug;
315 | };
316 | DBCE8D511D8DD5160012B477 /* Release */ = {
317 | isa = XCBuildConfiguration;
318 | buildSettings = {
319 | ALWAYS_SEARCH_USER_PATHS = NO;
320 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
321 | CLANG_ANALYZER_NONNULL = YES;
322 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
323 | CLANG_CXX_LIBRARY = "libc++";
324 | CLANG_ENABLE_MODULES = YES;
325 | CLANG_ENABLE_OBJC_ARC = YES;
326 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
327 | CLANG_WARN_BOOL_CONVERSION = YES;
328 | CLANG_WARN_COMMA = YES;
329 | CLANG_WARN_CONSTANT_CONVERSION = YES;
330 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
331 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
332 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
333 | CLANG_WARN_EMPTY_BODY = YES;
334 | CLANG_WARN_ENUM_CONVERSION = YES;
335 | CLANG_WARN_INFINITE_RECURSION = YES;
336 | CLANG_WARN_INT_CONVERSION = YES;
337 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
338 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
339 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
340 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
341 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES;
342 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
343 | CLANG_WARN_STRICT_PROTOTYPES = YES;
344 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
345 | CLANG_WARN_SUSPICIOUS_MOVES = YES;
346 | CLANG_WARN_UNREACHABLE_CODE = YES;
347 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
348 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
349 | COPY_PHASE_STRIP = NO;
350 | CURRENT_PROJECT_VERSION = 1;
351 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
352 | ENABLE_NS_ASSERTIONS = NO;
353 | ENABLE_STRICT_OBJC_MSGSEND = YES;
354 | GCC_C_LANGUAGE_STANDARD = gnu99;
355 | GCC_NO_COMMON_BLOCKS = YES;
356 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
357 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
358 | GCC_WARN_UNDECLARED_SELECTOR = YES;
359 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
360 | GCC_WARN_UNUSED_FUNCTION = YES;
361 | GCC_WARN_UNUSED_VARIABLE = YES;
362 | IPHONEOS_DEPLOYMENT_TARGET = 10.0;
363 | MTL_ENABLE_DEBUG_INFO = NO;
364 | SDKROOT = iphoneos;
365 | SWIFT_COMPILATION_MODE = wholemodule;
366 | SWIFT_OPTIMIZATION_LEVEL = "-O";
367 | SWIFT_VERSION = 5.0;
368 | TARGETED_DEVICE_FAMILY = "1,2";
369 | VALIDATE_PRODUCT = YES;
370 | VERSIONING_SYSTEM = "apple-generic";
371 | VERSION_INFO_PREFIX = "";
372 | };
373 | name = Release;
374 | };
375 | DBCE8D531D8DD5160012B477 /* Debug */ = {
376 | isa = XCBuildConfiguration;
377 | buildSettings = {
378 | CLANG_ENABLE_MODULES = YES;
379 | CODE_SIGN_IDENTITY = "";
380 | DEFINES_MODULE = YES;
381 | DEVELOPMENT_TEAM = 5549XPMRDN;
382 | DYLIB_COMPATIBILITY_VERSION = 1;
383 | DYLIB_CURRENT_VERSION = 1;
384 | DYLIB_INSTALL_NAME_BASE = "@rpath";
385 | INFOPLIST_FILE = SwiftEventBus/Info.plist;
386 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
387 | LD_RUNPATH_SEARCH_PATHS = (
388 | "$(inherited)",
389 | "@executable_path/Frameworks",
390 | "@loader_path/Frameworks",
391 | );
392 | PRODUCT_BUNDLE_IDENTIFIER = cesarferreira.SwiftEventBus;
393 | PRODUCT_NAME = "$(TARGET_NAME)";
394 | SKIP_INSTALL = YES;
395 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
396 | };
397 | name = Debug;
398 | };
399 | DBCE8D541D8DD5160012B477 /* Release */ = {
400 | isa = XCBuildConfiguration;
401 | buildSettings = {
402 | CLANG_ENABLE_MODULES = YES;
403 | CODE_SIGN_IDENTITY = "";
404 | DEFINES_MODULE = YES;
405 | DEVELOPMENT_TEAM = 5549XPMRDN;
406 | DYLIB_COMPATIBILITY_VERSION = 1;
407 | DYLIB_CURRENT_VERSION = 1;
408 | DYLIB_INSTALL_NAME_BASE = "@rpath";
409 | INFOPLIST_FILE = SwiftEventBus/Info.plist;
410 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
411 | LD_RUNPATH_SEARCH_PATHS = (
412 | "$(inherited)",
413 | "@executable_path/Frameworks",
414 | "@loader_path/Frameworks",
415 | );
416 | PRODUCT_BUNDLE_IDENTIFIER = cesarferreira.SwiftEventBus;
417 | PRODUCT_NAME = "$(TARGET_NAME)";
418 | SKIP_INSTALL = YES;
419 | };
420 | name = Release;
421 | };
422 | DBCE8D6B1D8DD88A0012B477 /* Debug */ = {
423 | isa = XCBuildConfiguration;
424 | buildSettings = {
425 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
426 | DEVELOPMENT_TEAM = 5549XPMRDN;
427 | INFOPLIST_FILE = Sample/Info.plist;
428 | LD_RUNPATH_SEARCH_PATHS = (
429 | "$(inherited)",
430 | "@executable_path/Frameworks",
431 | );
432 | PRODUCT_BUNDLE_IDENTIFIER = cesarferreira.Sample;
433 | PRODUCT_NAME = "$(TARGET_NAME)";
434 | };
435 | name = Debug;
436 | };
437 | DBCE8D6C1D8DD88A0012B477 /* Release */ = {
438 | isa = XCBuildConfiguration;
439 | buildSettings = {
440 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
441 | DEVELOPMENT_TEAM = 5549XPMRDN;
442 | INFOPLIST_FILE = Sample/Info.plist;
443 | LD_RUNPATH_SEARCH_PATHS = (
444 | "$(inherited)",
445 | "@executable_path/Frameworks",
446 | );
447 | PRODUCT_BUNDLE_IDENTIFIER = cesarferreira.Sample;
448 | PRODUCT_NAME = "$(TARGET_NAME)";
449 | };
450 | name = Release;
451 | };
452 | /* End XCBuildConfiguration section */
453 |
454 | /* Begin XCConfigurationList section */
455 | DBCE8D441D8DD5160012B477 /* Build configuration list for PBXProject "SwiftEventBus" */ = {
456 | isa = XCConfigurationList;
457 | buildConfigurations = (
458 | DBCE8D501D8DD5160012B477 /* Debug */,
459 | DBCE8D511D8DD5160012B477 /* Release */,
460 | );
461 | defaultConfigurationIsVisible = 0;
462 | defaultConfigurationName = Release;
463 | };
464 | DBCE8D521D8DD5160012B477 /* Build configuration list for PBXNativeTarget "SwiftEventBus" */ = {
465 | isa = XCConfigurationList;
466 | buildConfigurations = (
467 | DBCE8D531D8DD5160012B477 /* Debug */,
468 | DBCE8D541D8DD5160012B477 /* Release */,
469 | );
470 | defaultConfigurationIsVisible = 0;
471 | defaultConfigurationName = Release;
472 | };
473 | DBCE8D6A1D8DD88A0012B477 /* Build configuration list for PBXNativeTarget "Sample" */ = {
474 | isa = XCConfigurationList;
475 | buildConfigurations = (
476 | DBCE8D6B1D8DD88A0012B477 /* Debug */,
477 | DBCE8D6C1D8DD88A0012B477 /* Release */,
478 | );
479 | defaultConfigurationIsVisible = 0;
480 | defaultConfigurationName = Release;
481 | };
482 | /* End XCConfigurationList section */
483 | };
484 | rootObject = DBCE8D411D8DD5160012B477 /* Project object */;
485 | }
486 |
--------------------------------------------------------------------------------
/SwiftEventBus.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SwiftEventBus.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/SwiftEventBus.xcodeproj/xcshareddata/xcschemes/SwiftEventBus.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
43 |
44 |
50 |
51 |
52 |
53 |
59 |
60 |
66 |
67 |
68 |
69 |
71 |
72 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/SwiftEventBus/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | FMWK
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 | NSPrincipalClass
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/SwiftEventBus/SwiftEventBus.h:
--------------------------------------------------------------------------------
1 | //
2 | // SwiftEventBus.h
3 | // SwiftEventBus
4 | //
5 | // Created by Cesar Ferreira on 17/09/2016.
6 | // Copyright © 2016 Cesar Ferreira. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | //! Project version number for SwiftEventBus.
12 | FOUNDATION_EXPORT double SwiftEventBusVersionNumber;
13 |
14 | //! Project version string for SwiftEventBus.
15 | FOUNDATION_EXPORT const unsigned char SwiftEventBusVersionString[];
16 |
17 | // In this header, you should import all the public headers of your framework using statements like #import
18 |
19 |
20 |
--------------------------------------------------------------------------------
/SwiftEventBus/SwiftEventBus.swift:
--------------------------------------------------------------------------------
1 | import Foundation
2 |
3 | open class SwiftEventBus {
4 |
5 | struct Static {
6 | static let instance = SwiftEventBus()
7 | static let queue = DispatchQueue(label: "com.cesarferreira.SwiftEventBus", attributes: [])
8 | }
9 |
10 | struct NamedObserver {
11 | let observer: NSObjectProtocol
12 | let name: String
13 | }
14 |
15 | var cache = [UInt:[NamedObserver]]()
16 |
17 |
18 | ////////////////////////////////////
19 | // Publish
20 | ////////////////////////////////////
21 |
22 |
23 | open class func post(_ name: String, sender: Any? = nil) {
24 | NotificationCenter.default.post(name: Notification.Name(rawValue: name), object: sender)
25 | }
26 |
27 | open class func post(_ name: String, sender: NSObject?) {
28 | NotificationCenter.default.post(name: Notification.Name(rawValue: name), object: sender)
29 | }
30 |
31 | open class func post(_ name: String, sender: Any? = nil, userInfo: [AnyHashable: Any]?) {
32 | NotificationCenter.default.post(name: Notification.Name(rawValue: name), object: sender, userInfo: userInfo)
33 | }
34 |
35 | open class func postToMainThread(_ name: String, sender: Any? = nil) {
36 | DispatchQueue.main.async {
37 | NotificationCenter.default.post(name: Notification.Name(rawValue: name), object: sender)
38 | }
39 | }
40 |
41 | open class func postToMainThread(_ name: String, sender: NSObject?) {
42 | DispatchQueue.main.async {
43 | NotificationCenter.default.post(name: Notification.Name(rawValue: name), object: sender)
44 | }
45 | }
46 |
47 | open class func postToMainThread(_ name: String, sender: Any? = nil, userInfo: [AnyHashable: Any]?) {
48 | DispatchQueue.main.async {
49 | NotificationCenter.default.post(name: Notification.Name(rawValue: name), object: sender, userInfo: userInfo)
50 | }
51 | }
52 |
53 |
54 |
55 | ////////////////////////////////////
56 | // Subscribe
57 | ////////////////////////////////////
58 |
59 | @discardableResult
60 | open class func on(_ target: AnyObject, name: String, sender: Any? = nil, queue: OperationQueue?, handler: @escaping ((Notification?) -> Void)) -> NSObjectProtocol {
61 | let id = UInt(bitPattern: ObjectIdentifier(target))
62 | let observer = NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: name), object: sender, queue: queue, using: handler)
63 | let namedObserver = NamedObserver(observer: observer, name: name)
64 |
65 | Static.queue.sync {
66 | if let namedObservers = Static.instance.cache[id] {
67 | Static.instance.cache[id] = namedObservers + [namedObserver]
68 | } else {
69 | Static.instance.cache[id] = [namedObserver]
70 | }
71 | }
72 |
73 | return observer
74 | }
75 |
76 | @discardableResult
77 | open class func onMainThread(_ target: AnyObject, name: String, sender: Any? = nil, handler: @escaping ((Notification?) -> Void)) -> NSObjectProtocol {
78 | return SwiftEventBus.on(target, name: name, sender: sender, queue: OperationQueue.main, handler: handler)
79 | }
80 |
81 | @discardableResult
82 | open class func onBackgroundThread(_ target: AnyObject, name: String, sender: Any? = nil, handler: @escaping ((Notification?) -> Void)) -> NSObjectProtocol {
83 | return SwiftEventBus.on(target, name: name, sender: sender, queue: OperationQueue(), handler: handler)
84 | }
85 |
86 | ////////////////////////////////////
87 | // Unregister
88 | ////////////////////////////////////
89 |
90 | open class func unregister(_ target: AnyObject) {
91 | let id = UInt(bitPattern: ObjectIdentifier(target))
92 | let center = NotificationCenter.default
93 |
94 | Static.queue.sync {
95 | if let namedObservers = Static.instance.cache.removeValue(forKey: id) {
96 | for namedObserver in namedObservers {
97 | center.removeObserver(namedObserver.observer)
98 | }
99 | }
100 | }
101 | }
102 |
103 | open class func unregister(_ target: AnyObject, name: String) {
104 | let id = UInt(bitPattern: ObjectIdentifier(target))
105 | let center = NotificationCenter.default
106 |
107 | Static.queue.sync {
108 | if let namedObservers = Static.instance.cache[id] {
109 | Static.instance.cache[id] = namedObservers.filter({ (namedObserver: NamedObserver) -> Bool in
110 | if namedObserver.name == name {
111 | center.removeObserver(namedObserver.observer)
112 | return false
113 | } else {
114 | return true
115 | }
116 | })
117 | }
118 | }
119 | }
120 |
121 | }
122 |
--------------------------------------------------------------------------------