├── .gitignore
├── .swift-version
├── .travis.yml
├── EventBus iOS
├── AppDelegate.swift
├── Assets.xcassets
│ ├── AppIcon.appiconset
│ │ ├── Contents.json
│ │ ├── Icon-60@2x.png
│ │ ├── Icon-60@3x.png
│ │ ├── Icon-76.png
│ │ ├── Icon-76@2x.png
│ │ ├── Icon-83.5@2x.png
│ │ ├── Icon-Notification.png
│ │ ├── Icon-Notification@2x.png
│ │ ├── Icon-Notification@3x.png
│ │ ├── Icon-Small-40.png
│ │ ├── Icon-Small-40@2x.png
│ │ ├── Icon-Small-40@3x.png
│ │ ├── Icon-Small.png
│ │ ├── Icon-Small@2x.png
│ │ └── Icon-Small@3x.png
│ ├── AppIcon.png
│ ├── Contents.json
│ └── diagram.imageset
│ │ ├── Contents.json
│ │ └── diagram.pdf
├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
├── Info.plist
└── ViewController.swift
├── EventBus.xcodeproj
├── Configs
│ └── Universal.xcconfig
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcshareddata
│ │ └── IDEWorkspaceChecks.plist
└── xcshareddata
│ └── xcschemes
│ ├── EventBus (Static).xcscheme
│ └── EventBus.xcscheme
├── EventBus
├── ErrorHandler.swift
├── Errors.swift
├── EventBus.swift
├── EventChainable.swift
├── EventNotifiable.swift
├── EventRegistrable.swift
├── EventSubscribable.swift
├── Info.plist
├── LogHandler.swift
├── NSLocking+Extensions.swift
└── Options.swift
├── EventBusTests
├── EventChainableTests.swift
├── EventNotifiableTests.swift
├── EventSubscribableTests.swift
├── Info.plist
└── Utilities.swift
├── Icon.sketch
├── LICENSE
├── README.md
├── Swift-EventBus.podspec
├── jumbotron.png
└── screencast.gif
/.gitignore:
--------------------------------------------------------------------------------
1 |
2 | # Created by https://www.gitignore.io/api/swift
3 |
4 | ### Swift ###
5 | # Xcode
6 | #
7 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
8 |
9 | ## Build generated
10 | build/
11 | DerivedData/
12 |
13 | ## Various settings
14 | *.pbxuser
15 | !default.pbxuser
16 | *.mode1v3
17 | !default.mode1v3
18 | *.mode2v3
19 | !default.mode2v3
20 | *.perspectivev3
21 | !default.perspectivev3
22 | xcuserdata/
23 |
24 | ## Other
25 | *.moved-aside
26 | *.xccheckout
27 | *.xcscmblueprint
28 |
29 | ## Obj-C/Swift specific
30 | *.hmap
31 | *.ipa
32 | *.dSYM.zip
33 | *.dSYM
34 |
35 | ## Playgrounds
36 | timeline.xctimeline
37 | playground.xcworkspace
38 |
39 | # Swift Package Manager
40 | #
41 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
42 | # Packages/
43 | # Package.pins
44 | .build/
45 |
46 | # CocoaPods
47 | #
48 | # We recommend against adding the Pods directory to your .gitignore. However
49 | # you should judge for yourself, the pros and cons are mentioned at:
50 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
51 | #
52 | # Pods/
53 |
54 | # Carthage
55 | #
56 | # Add this line if you want to avoid checking in source code from Carthage dependencies.
57 | Carthage/Checkouts
58 | Carthage/Build
59 |
60 | # fastlane
61 | #
62 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the
63 | # screenshots whenever they are needed.
64 | # For more information about the recommended setup visit:
65 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md
66 |
67 | fastlane/report.xml
68 | fastlane/Preview.html
69 | fastlane/screenshots
70 | fastlane/test_output
71 |
72 | # End of https://www.gitignore.io/api/swift
73 |
74 | .DS_Store
75 |
--------------------------------------------------------------------------------
/.swift-version:
--------------------------------------------------------------------------------
1 | 4.1
2 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: swift
2 | osx_image: xcode9.3beta
3 | script:
4 | - xcodebuild -scheme EventBus -project EventBus.xcodeproj -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 6,OS=11.3' build test
5 |
--------------------------------------------------------------------------------
/EventBus iOS/AppDelegate.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import UIKit
6 |
7 | import EventBus
8 |
9 | @UIApplicationMain
10 | class AppDelegate: UIResponder, UIApplicationDelegate {
11 |
12 | var window: UIWindow?
13 |
14 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
15 | // Override point for customization after application launch.
16 |
17 | EventBus.isStrict = true
18 |
19 | return true
20 | }
21 |
22 | func applicationWillResignActive(_ application: UIApplication) {
23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
25 | }
26 |
27 | func applicationDidEnterBackground(_ application: UIApplication) {
28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
30 | }
31 |
32 | func applicationWillEnterForeground(_ application: UIApplication) {
33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
34 | }
35 |
36 | func applicationDidBecomeActive(_ application: UIApplication) {
37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
38 | }
39 |
40 | func applicationWillTerminate(_ application: UIApplication) {
41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "size" : "20x20",
5 | "idiom" : "iphone",
6 | "filename" : "Icon-Notification@2x.png",
7 | "scale" : "2x"
8 | },
9 | {
10 | "size" : "20x20",
11 | "idiom" : "iphone",
12 | "filename" : "Icon-Notification@3x.png",
13 | "scale" : "3x"
14 | },
15 | {
16 | "size" : "29x29",
17 | "idiom" : "iphone",
18 | "filename" : "Icon-Small@2x.png",
19 | "scale" : "2x"
20 | },
21 | {
22 | "size" : "29x29",
23 | "idiom" : "iphone",
24 | "filename" : "Icon-Small@3x.png",
25 | "scale" : "3x"
26 | },
27 | {
28 | "size" : "40x40",
29 | "idiom" : "iphone",
30 | "filename" : "Icon-Small-40@2x.png",
31 | "scale" : "2x"
32 | },
33 | {
34 | "size" : "40x40",
35 | "idiom" : "iphone",
36 | "filename" : "Icon-Small-40@3x.png",
37 | "scale" : "3x"
38 | },
39 | {
40 | "size" : "60x60",
41 | "idiom" : "iphone",
42 | "filename" : "Icon-60@2x.png",
43 | "scale" : "2x"
44 | },
45 | {
46 | "size" : "60x60",
47 | "idiom" : "iphone",
48 | "filename" : "Icon-60@3x.png",
49 | "scale" : "3x"
50 | },
51 | {
52 | "size" : "20x20",
53 | "idiom" : "ipad",
54 | "filename" : "Icon-Notification.png",
55 | "scale" : "1x"
56 | },
57 | {
58 | "size" : "20x20",
59 | "idiom" : "ipad",
60 | "filename" : "Icon-Notification@2x.png",
61 | "scale" : "2x"
62 | },
63 | {
64 | "size" : "29x29",
65 | "idiom" : "ipad",
66 | "filename" : "Icon-Small.png",
67 | "scale" : "1x"
68 | },
69 | {
70 | "size" : "29x29",
71 | "idiom" : "ipad",
72 | "filename" : "Icon-Small@2x.png",
73 | "scale" : "2x"
74 | },
75 | {
76 | "size" : "40x40",
77 | "idiom" : "ipad",
78 | "filename" : "Icon-Small-40.png",
79 | "scale" : "1x"
80 | },
81 | {
82 | "size" : "40x40",
83 | "idiom" : "ipad",
84 | "filename" : "Icon-Small-40@2x.png",
85 | "scale" : "2x"
86 | },
87 | {
88 | "size" : "76x76",
89 | "idiom" : "ipad",
90 | "filename" : "Icon-76.png",
91 | "scale" : "1x"
92 | },
93 | {
94 | "size" : "76x76",
95 | "idiom" : "ipad",
96 | "filename" : "Icon-76@2x.png",
97 | "scale" : "2x"
98 | },
99 | {
100 | "size" : "83.5x83.5",
101 | "idiom" : "ipad",
102 | "filename" : "Icon-83.5@2x.png",
103 | "scale" : "2x"
104 | },
105 | {
106 | "idiom" : "ios-marketing",
107 | "size" : "1024x1024",
108 | "scale" : "1x"
109 | }
110 | ],
111 | "info" : {
112 | "version" : 1,
113 | "author" : "xcode"
114 | }
115 | }
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-60@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-60@2x.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-60@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-60@3x.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-76.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-76.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-76@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-76@2x.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-83.5@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-83.5@2x.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Notification.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Notification.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Notification@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Notification@2x.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Notification@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Notification@3x.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Small-40.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Small-40.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Small-40@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Small-40@2x.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Small-40@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Small-40@3x.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Small.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Small.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Small@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Small@2x.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Small@3x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.appiconset/Icon-Small@3x.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/AppIcon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/AppIcon.png
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "info" : {
3 | "version" : 1,
4 | "author" : "xcode"
5 | }
6 | }
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/diagram.imageset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "universal",
5 | "filename" : "diagram.pdf"
6 | }
7 | ],
8 | "info" : {
9 | "version" : 1,
10 | "author" : "xcode"
11 | }
12 | }
--------------------------------------------------------------------------------
/EventBus iOS/Assets.xcassets/diagram.imageset/diagram.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/EventBus iOS/Assets.xcassets/diagram.imageset/diagram.pdf
--------------------------------------------------------------------------------
/EventBus iOS/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 |
--------------------------------------------------------------------------------
/EventBus iOS/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 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
--------------------------------------------------------------------------------
/EventBus iOS/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleDisplayName
8 | EventBus
9 | CFBundleExecutable
10 | $(EXECUTABLE_NAME)
11 | CFBundleIdentifier
12 | $(PRODUCT_BUNDLE_IDENTIFIER)
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | $(PRODUCT_NAME)
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleVersion
22 | 1
23 | LSRequiresIPhoneOS
24 |
25 | UILaunchStoryboardName
26 | LaunchScreen
27 | UIMainStoryboardFile
28 | Main
29 | UIRequiredDeviceCapabilities
30 |
31 | armv7
32 |
33 | UISupportedInterfaceOrientations
34 |
35 | UIInterfaceOrientationPortrait
36 | UIInterfaceOrientationLandscapeLeft
37 | UIInterfaceOrientationLandscapeRight
38 |
39 | UISupportedInterfaceOrientations~ipad
40 |
41 | UIInterfaceOrientationPortrait
42 | UIInterfaceOrientationPortraitUpsideDown
43 | UIInterfaceOrientationLandscapeLeft
44 | UIInterfaceOrientationLandscapeRight
45 |
46 |
47 |
48 |
--------------------------------------------------------------------------------
/EventBus iOS/ViewController.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import UIKit
6 |
7 | import EventBus
8 |
9 | protocol Event {
10 | func handle(after: TimeInterval)
11 | }
12 |
13 | class Subscriber {
14 | let eventSubscribable: EventSubscribable
15 | let view: UIView
16 |
17 | init(eventSubscribable: EventSubscribable, view: UIView) {
18 | self.eventSubscribable = eventSubscribable
19 | self.view = view
20 |
21 | self.eventSubscribable.add(subscriber: self, for: Event.self)
22 | }
23 | }
24 |
25 | extension Subscriber: Event {
26 | func handle(after delay: TimeInterval) {
27 | DispatchQueue.main.asyncAfter(deadline: .now() + delay) {
28 | let backgroundColor = self.view.backgroundColor
29 | UIView.animate(withDuration: 0.25, animations: {
30 | self.view.backgroundColor = UIColor.red
31 | }, completion: { _ in
32 | UIView.animate(withDuration: 0.5) {
33 | self.view.backgroundColor = backgroundColor
34 | }
35 | })
36 | }
37 | }
38 | }
39 |
40 | @IBDesignable
41 | class RoundedRectView: UIView {
42 | override init(frame: CGRect) {
43 | super.init(frame: frame)
44 | self.commonInit()
45 | }
46 |
47 | required init?(coder: NSCoder) {
48 | super.init(coder: coder)
49 | self.commonInit()
50 | }
51 |
52 | func commonInit() {
53 | self.backgroundColor = UIColor(red: 0.2745, green: 0.5572, blue: 0.8976, alpha: 1.0)
54 | self.layer.cornerRadius = 10.0
55 | }
56 | }
57 |
58 | class ViewController: UIViewController {
59 |
60 | @IBOutlet var publisherView: RoundedRectView!
61 | @IBOutlet var eventBusView: RoundedRectView!
62 | @IBOutlet var subscriberViewTop: RoundedRectView!
63 | @IBOutlet var subscriberViewMiddle: RoundedRectView!
64 | @IBOutlet var subscriberViewBottom: RoundedRectView!
65 | @IBOutlet var diagramView: UIImageView!
66 | @IBOutlet var containerView: UIView!
67 |
68 | let eventBus: EventBus = .init(options: [.warnUnhandled])
69 | var timer: Timer!
70 |
71 | var subscribers: [Subscriber] = []
72 |
73 | override func viewDidLoad() {
74 | super.viewDidLoad()
75 |
76 | self.subscribers = [
77 | Subscriber(eventSubscribable: eventBus, view: self.subscriberViewTop),
78 | Subscriber(eventSubscribable: eventBus, view: self.subscriberViewMiddle),
79 | Subscriber(eventSubscribable: eventBus, view: self.subscriberViewBottom),
80 | ]
81 |
82 | self.timer = Timer.scheduledTimer(withTimeInterval: 3.0, repeats: true) { _ in
83 | self.ping()
84 | }
85 | self.timer.fire()
86 | }
87 |
88 | override func didReceiveMemoryWarning() {
89 | super.didReceiveMemoryWarning()
90 | // Dispose of any resources that can be recreated.
91 | }
92 |
93 | func ping() {
94 | self.eventBus.notify(Event.self) { subscriber in
95 | subscriber.handle(after: 2.0)
96 | }
97 |
98 | self.emitSignal(color: UIColor.red, onPath: {
99 | let path = UIBezierPath()
100 | path.move(to: self.publisherView.center)
101 | path.addLine(to: self.eventBusView.center)
102 | return path
103 | }())
104 |
105 | DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
106 | self.emitSignal(color: UIColor.red, onPath: {
107 | let startFrame = self.eventBusView.frame
108 | let endFrame = self.subscriberViewTop.frame
109 | let startPoint = CGPoint(x: startFrame.maxX, y: startFrame.midY)
110 | let endPoint = CGPoint(x: endFrame.minX, y: endFrame.midY)
111 | let path = UIBezierPath()
112 | path.move(to: self.eventBusView.center)
113 | path.addLine(to: startPoint)
114 | path.addCurve(
115 | to: startPoint.applying(.init(translationX: 10.0, y: -10.0)),
116 | controlPoint1: startPoint.applying(.init(translationX: 5.0, y: 0.0)),
117 | controlPoint2: startPoint.applying(.init(translationX: 10.0, y: -5.0))
118 | )
119 | path.addLine(to: startPoint.applying(.init(translationX: 10.0, y: -50.0)))
120 | path.addCurve(
121 | to: endPoint,
122 | controlPoint1: endPoint.applying(.init(translationX: -10.0, y: 5.0)),
123 | controlPoint2: endPoint.applying(.init(translationX: -5.0, y: 0.0))
124 | )
125 | path.addLine(to: self.subscriberViewTop.center)
126 | return path
127 | }())
128 | }
129 |
130 | DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
131 | self.emitSignal(color: UIColor.red, onPath: {
132 | let path = UIBezierPath()
133 | path.move(to: self.eventBusView.center)
134 | path.addLine(to: self.subscriberViewMiddle.center)
135 | return path
136 | }())
137 | }
138 |
139 | DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
140 | self.emitSignal(color: UIColor.red, onPath: {
141 | let startFrame = self.eventBusView.frame
142 | let endFrame = self.subscriberViewBottom.frame
143 | let startPoint = CGPoint(x: startFrame.maxX, y: startFrame.midY)
144 | let endPoint = CGPoint(x: endFrame.minX, y: endFrame.midY)
145 | let path = UIBezierPath()
146 | path.move(to: self.eventBusView.center)
147 | path.addLine(to: startPoint)
148 | path.addCurve(
149 | to: startPoint.applying(.init(translationX: 10.0, y: 10.0)),
150 | controlPoint1: startPoint.applying(.init(translationX: 5.0, y: 0.0)),
151 | controlPoint2: startPoint.applying(.init(translationX: 10.0, y: 5.0))
152 | )
153 | path.addLine(to: startPoint.applying(.init(translationX: 10.0, y: 50.0)))
154 | path.addCurve(
155 | to: endPoint,
156 | controlPoint1: endPoint.applying(.init(translationX: -10.0, y: -5.0)),
157 | controlPoint2: endPoint.applying(.init(translationX: -5.0, y: 0.0))
158 | )
159 | path.addLine(to: self.subscriberViewBottom.center)
160 | return path
161 | }())
162 | }
163 | }
164 |
165 | func emitSignal(color: UIColor, onPath animationPath: UIBezierPath) {
166 | let signalLayer = CALayer()
167 | signalLayer.backgroundColor = color.cgColor
168 | signalLayer.bounds = CGRect(origin: CGPoint(), size: CGSize(width: 10.0, height: 10.0))
169 | signalLayer.cornerRadius = 5.0
170 | signalLayer.position = self.publisherView.center
171 | signalLayer.opacity = 0.0
172 |
173 | let positionAnimation = CAKeyframeAnimation(keyPath: "position")
174 | positionAnimation.path = animationPath.cgPath
175 |
176 | let opacityAnimation = CAKeyframeAnimation(keyPath: "opacity")
177 | opacityAnimation.values = [0.0, 1.0, 1.0, 0.0]
178 |
179 | let animationGroup = CAAnimationGroup()
180 | animationGroup.animations = [
181 | positionAnimation,
182 | opacityAnimation
183 | ]
184 | animationGroup.repeatCount = 1
185 | animationGroup.duration = 1.0
186 | animationGroup.delegate = AnimationDelegate(layer: signalLayer)
187 |
188 | signalLayer.add(animationGroup, forKey: nil)
189 | self.containerView.layer.addSublayer(signalLayer)
190 | }
191 | }
192 |
193 | class AnimationDelegate: NSObject {
194 |
195 | let layer: CALayer
196 |
197 | init(layer: CALayer) {
198 | self.layer = layer
199 | }
200 | }
201 |
202 | extension AnimationDelegate: CAAnimationDelegate {
203 | func animationDidStart(_ animation: CAAnimation) {
204 | // Do nothing
205 | }
206 |
207 | func animationDidStop(_ animation: CAAnimation, finished: Bool) {
208 | self.layer.removeFromSuperlayer()
209 | }
210 | }
211 |
--------------------------------------------------------------------------------
/EventBus.xcodeproj/Configs/Universal.xcconfig:
--------------------------------------------------------------------------------
1 | PRODUCT_NAME = $(TARGET_NAME)
2 | SUPPORTED_PLATFORMS = macosx iphoneos iphonesimulator appletvos appletvsimulator watchos watchsimulator
3 | DYLIB_INSTALL_NAME_BASE = @rpath
4 | OTHER_SWIFT_FLAGS = -DXcode
5 |
6 | SDKROOT[sdk=iphone*] = iphoneos
7 | VALID_ARCHS[sdk=iphone*] = arm64 armv7 armv7s
8 | IPHONEOS_DEPLOYMENT_TARGET = 9.0
9 | TARGETED_DEVICE_FAMILY[sdk=iphone*] = 1,2
10 | LD_RUNPATH_SEARCH_PATHS[sdk=iphone*] = $(inherited) @executable_path/Frameworks @loader_path/Frameworks
11 |
12 | SDKROOT[sdk=appletv*] = appletvos
13 | TVOS_DEPLOYMENT_TARGET = 10.0
14 | TARGETED_DEVICE_FAMILY[sdk=appletv*] = 3
15 | LD_RUNPATH_SEARCH_PATHS[sdk=appletv*] = $(inherited) @executable_path/Frameworks @loader_path/Frameworks
16 |
17 | SDKROOT[sdk=watch*] = watchos
18 | WATCHOS_DEPLOYMENT_TARGET = 3.0
19 | TARGETED_DEVICE_FAMILY[sdk=watch*] = 4
20 | LD_RUNPATH_SEARCH_PATHS[sdk=watch*] = $(inherited) @executable_path/Frameworks @loader_path/Frameworks
21 |
22 | SDKROOT[sdk=macosx*] = macosx
23 | VALID_ARCHS[sdk=macosx*] = x86_64
24 | MACOSX_DEPLOYMENT_TARGET = 10.11
25 | LD_RUNPATH_SEARCH_PATHS[sdk=macosx*] = $(inherited) @executable_path/../Frameworks @loader_path/../Frameworks
26 |
--------------------------------------------------------------------------------
/EventBus.xcodeproj/project.pbxproj:
--------------------------------------------------------------------------------
1 | // !$*UTF8*$!
2 | {
3 | archiveVersion = 1;
4 | classes = {
5 | };
6 | objectVersion = 46;
7 | objects = {
8 |
9 | /* Begin PBXBuildFile section */
10 | BF2118441DF488DF00FF863D /* EventSubscribableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF2118431DF488DF00FF863D /* EventSubscribableTests.swift */; };
11 | BF2118581DF5772800FF863D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF2118571DF5772800FF863D /* AppDelegate.swift */; };
12 | BF21185A1DF5772800FF863D /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF2118591DF5772800FF863D /* ViewController.swift */; };
13 | BF21185D1DF5772800FF863D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BF21185B1DF5772800FF863D /* Main.storyboard */; };
14 | BF21185F1DF5772800FF863D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = BF21185E1DF5772800FF863D /* Assets.xcassets */; };
15 | BF2118621DF5772800FF863D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = BF2118601DF5772800FF863D /* LaunchScreen.storyboard */; };
16 | BF4B82471F41AD21009A317D /* EventBus.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF21184F1DF488F800FF863D /* EventBus.swift */; };
17 | BF851B801F5D80570042DD59 /* libEventBus.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BF4B823E1F41ACC1009A317D /* libEventBus.a */; };
18 | BF851B821F5D94B00042DD59 /* EventNotifiableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF851B811F5D94B00042DD59 /* EventNotifiableTests.swift */; };
19 | BF9142E41DF57F4300040556 /* EventBus.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BF2118351DF488DF00FF863D /* EventBus.framework */; };
20 | BF9142E51DF57F4300040556 /* EventBus.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BF2118351DF488DF00FF863D /* EventBus.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
21 | BF9858582138335E0033C15D /* NSLocking+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF9858572138335E0033C15D /* NSLocking+Extensions.swift */; };
22 | BF985859213835110033C15D /* NSLocking+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF9858572138335E0033C15D /* NSLocking+Extensions.swift */; };
23 | BFBBACF32121CE88001F96DD /* EventRegistrable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACF22121CE88001F96DD /* EventRegistrable.swift */; };
24 | BFBBACF52121CED7001F96DD /* EventSubscribable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACF42121CED7001F96DD /* EventSubscribable.swift */; };
25 | BFBBACF72121CEE6001F96DD /* EventChainable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACF62121CEE6001F96DD /* EventChainable.swift */; };
26 | BFBBACF92121CEF6001F96DD /* EventNotifiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACF82121CEF6001F96DD /* EventNotifiable.swift */; };
27 | BFBBACFB2121CF03001F96DD /* Options.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACFA2121CF03001F96DD /* Options.swift */; };
28 | BFBBACFD2121CF0E001F96DD /* ErrorHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACFC2121CF0E001F96DD /* ErrorHandler.swift */; };
29 | BFBBACFF2121CF27001F96DD /* LogHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACFE2121CF27001F96DD /* LogHandler.swift */; };
30 | BFBBAD012121CF3C001F96DD /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBAD002121CF3C001F96DD /* Errors.swift */; };
31 | BFBBAD022121D091001F96DD /* EventRegistrable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACF22121CE88001F96DD /* EventRegistrable.swift */; };
32 | BFBBAD032121D091001F96DD /* EventSubscribable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACF42121CED7001F96DD /* EventSubscribable.swift */; };
33 | BFBBAD042121D091001F96DD /* EventChainable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACF62121CEE6001F96DD /* EventChainable.swift */; };
34 | BFBBAD052121D091001F96DD /* EventNotifiable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACF82121CEF6001F96DD /* EventNotifiable.swift */; };
35 | BFBBAD062121D091001F96DD /* Options.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACFA2121CF03001F96DD /* Options.swift */; };
36 | BFBBAD072121D091001F96DD /* ErrorHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACFC2121CF0E001F96DD /* ErrorHandler.swift */; };
37 | BFBBAD082121D091001F96DD /* LogHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBACFE2121CF27001F96DD /* LogHandler.swift */; };
38 | BFBBAD092121D091001F96DD /* Errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFBBAD002121CF3C001F96DD /* Errors.swift */; };
39 | BFF704081F5D976A00DFF413 /* EventBus.swift in Sources */ = {isa = PBXBuildFile; fileRef = BF21184F1DF488F800FF863D /* EventBus.swift */; };
40 | BFF7040A1F5D97F100DFF413 /* EventChainableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF704091F5D97F100DFF413 /* EventChainableTests.swift */; };
41 | BFF7040C1F5D981100DFF413 /* Utilities.swift in Sources */ = {isa = PBXBuildFile; fileRef = BFF7040B1F5D981100DFF413 /* Utilities.swift */; };
42 | /* End PBXBuildFile section */
43 |
44 | /* Begin PBXContainerItemProxy section */
45 | BF2118401DF488DF00FF863D /* PBXContainerItemProxy */ = {
46 | isa = PBXContainerItemProxy;
47 | containerPortal = BF21182C1DF488DF00FF863D /* Project object */;
48 | proxyType = 1;
49 | remoteGlobalIDString = BF2118341DF488DF00FF863D;
50 | remoteInfo = EventBus;
51 | };
52 | BF9142E61DF57F4300040556 /* PBXContainerItemProxy */ = {
53 | isa = PBXContainerItemProxy;
54 | containerPortal = BF21182C1DF488DF00FF863D /* Project object */;
55 | proxyType = 1;
56 | remoteGlobalIDString = BF2118341DF488DF00FF863D;
57 | remoteInfo = EventBus;
58 | };
59 | /* End PBXContainerItemProxy section */
60 |
61 | /* Begin PBXCopyFilesBuildPhase section */
62 | BF4B823C1F41ACC1009A317D /* CopyFiles */ = {
63 | isa = PBXCopyFilesBuildPhase;
64 | buildActionMask = 2147483647;
65 | dstPath = "include/$(PRODUCT_NAME)";
66 | dstSubfolderSpec = 16;
67 | files = (
68 | );
69 | runOnlyForDeploymentPostprocessing = 0;
70 | };
71 | BF9142E81DF57F4300040556 /* Embed Frameworks */ = {
72 | isa = PBXCopyFilesBuildPhase;
73 | buildActionMask = 2147483647;
74 | dstPath = "";
75 | dstSubfolderSpec = 10;
76 | files = (
77 | BF9142E51DF57F4300040556 /* EventBus.framework in Embed Frameworks */,
78 | );
79 | name = "Embed Frameworks";
80 | runOnlyForDeploymentPostprocessing = 0;
81 | };
82 | /* End PBXCopyFilesBuildPhase section */
83 |
84 | /* Begin PBXFileReference section */
85 | BF2118351DF488DF00FF863D /* EventBus.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = EventBus.framework; sourceTree = BUILT_PRODUCTS_DIR; };
86 | BF2118391DF488DF00FF863D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
87 | BF21183E1DF488DF00FF863D /* EventBusTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = EventBusTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
88 | BF2118431DF488DF00FF863D /* EventSubscribableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventSubscribableTests.swift; sourceTree = ""; };
89 | BF2118451DF488DF00FF863D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
90 | BF21184F1DF488F800FF863D /* EventBus.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventBus.swift; sourceTree = ""; };
91 | BF2118551DF5772800FF863D /* EventBus iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "EventBus iOS.app"; sourceTree = BUILT_PRODUCTS_DIR; };
92 | BF2118571DF5772800FF863D /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; };
93 | BF2118591DF5772800FF863D /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; };
94 | BF21185C1DF5772800FF863D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; };
95 | BF21185E1DF5772800FF863D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; };
96 | BF2118611DF5772800FF863D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; };
97 | BF2118631DF5772800FF863D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; };
98 | BF4B823E1F41ACC1009A317D /* libEventBus.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libEventBus.a; sourceTree = BUILT_PRODUCTS_DIR; };
99 | BF851B811F5D94B00042DD59 /* EventNotifiableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventNotifiableTests.swift; sourceTree = ""; };
100 | BF9858572138335E0033C15D /* NSLocking+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSLocking+Extensions.swift"; sourceTree = ""; };
101 | BFBBACF22121CE88001F96DD /* EventRegistrable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventRegistrable.swift; sourceTree = ""; };
102 | BFBBACF42121CED7001F96DD /* EventSubscribable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventSubscribable.swift; sourceTree = ""; };
103 | BFBBACF62121CEE6001F96DD /* EventChainable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventChainable.swift; sourceTree = ""; };
104 | BFBBACF82121CEF6001F96DD /* EventNotifiable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventNotifiable.swift; sourceTree = ""; };
105 | BFBBACFA2121CF03001F96DD /* Options.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Options.swift; sourceTree = ""; };
106 | BFBBACFC2121CF0E001F96DD /* ErrorHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ErrorHandler.swift; sourceTree = ""; };
107 | BFBBACFE2121CF27001F96DD /* LogHandler.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogHandler.swift; sourceTree = ""; };
108 | BFBBAD002121CF3C001F96DD /* Errors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Errors.swift; sourceTree = ""; };
109 | BFE7A7551E64B89600F51068 /* Universal.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Universal.xcconfig; sourceTree = ""; };
110 | BFF704091F5D97F100DFF413 /* EventChainableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventChainableTests.swift; sourceTree = ""; };
111 | BFF7040B1F5D981100DFF413 /* Utilities.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utilities.swift; sourceTree = ""; };
112 | /* End PBXFileReference section */
113 |
114 | /* Begin PBXFrameworksBuildPhase section */
115 | BF2118311DF488DF00FF863D /* Frameworks */ = {
116 | isa = PBXFrameworksBuildPhase;
117 | buildActionMask = 2147483647;
118 | files = (
119 | );
120 | runOnlyForDeploymentPostprocessing = 0;
121 | };
122 | BF21183B1DF488DF00FF863D /* Frameworks */ = {
123 | isa = PBXFrameworksBuildPhase;
124 | buildActionMask = 2147483647;
125 | files = (
126 | BF851B801F5D80570042DD59 /* libEventBus.a in Frameworks */,
127 | );
128 | runOnlyForDeploymentPostprocessing = 0;
129 | };
130 | BF2118521DF5772800FF863D /* Frameworks */ = {
131 | isa = PBXFrameworksBuildPhase;
132 | buildActionMask = 2147483647;
133 | files = (
134 | BF9142E41DF57F4300040556 /* EventBus.framework in Frameworks */,
135 | );
136 | runOnlyForDeploymentPostprocessing = 0;
137 | };
138 | BF4B823B1F41ACC1009A317D /* Frameworks */ = {
139 | isa = PBXFrameworksBuildPhase;
140 | buildActionMask = 2147483647;
141 | files = (
142 | );
143 | runOnlyForDeploymentPostprocessing = 0;
144 | };
145 | /* End PBXFrameworksBuildPhase section */
146 |
147 | /* Begin PBXGroup section */
148 | BF21182B1DF488DF00FF863D = {
149 | isa = PBXGroup;
150 | children = (
151 | BF2118371DF488DF00FF863D /* EventBus */,
152 | BF2118421DF488DF00FF863D /* EventBusTests */,
153 | BF2118561DF5772800FF863D /* EventBus iOS */,
154 | BFE7A7541E64B89500F51068 /* Configs */,
155 | BF2118361DF488DF00FF863D /* Products */,
156 | BF851B7E1F5D6D240042DD59 /* Frameworks */,
157 | );
158 | sourceTree = "";
159 | };
160 | BF2118361DF488DF00FF863D /* Products */ = {
161 | isa = PBXGroup;
162 | children = (
163 | BF2118351DF488DF00FF863D /* EventBus.framework */,
164 | BF21183E1DF488DF00FF863D /* EventBusTests.xctest */,
165 | BF2118551DF5772800FF863D /* EventBus iOS.app */,
166 | BF4B823E1F41ACC1009A317D /* libEventBus.a */,
167 | );
168 | name = Products;
169 | sourceTree = "";
170 | };
171 | BF2118371DF488DF00FF863D /* EventBus */ = {
172 | isa = PBXGroup;
173 | children = (
174 | BF21184F1DF488F800FF863D /* EventBus.swift */,
175 | BFBBACF22121CE88001F96DD /* EventRegistrable.swift */,
176 | BFBBACF42121CED7001F96DD /* EventSubscribable.swift */,
177 | BFBBACF62121CEE6001F96DD /* EventChainable.swift */,
178 | BFBBACF82121CEF6001F96DD /* EventNotifiable.swift */,
179 | BFBBACFA2121CF03001F96DD /* Options.swift */,
180 | BFBBACFC2121CF0E001F96DD /* ErrorHandler.swift */,
181 | BFBBACFE2121CF27001F96DD /* LogHandler.swift */,
182 | BFBBAD002121CF3C001F96DD /* Errors.swift */,
183 | BF9858572138335E0033C15D /* NSLocking+Extensions.swift */,
184 | BF2118391DF488DF00FF863D /* Info.plist */,
185 | );
186 | path = EventBus;
187 | sourceTree = "";
188 | };
189 | BF2118421DF488DF00FF863D /* EventBusTests */ = {
190 | isa = PBXGroup;
191 | children = (
192 | BFF7040B1F5D981100DFF413 /* Utilities.swift */,
193 | BF2118431DF488DF00FF863D /* EventSubscribableTests.swift */,
194 | BF851B811F5D94B00042DD59 /* EventNotifiableTests.swift */,
195 | BFF704091F5D97F100DFF413 /* EventChainableTests.swift */,
196 | BF2118451DF488DF00FF863D /* Info.plist */,
197 | );
198 | path = EventBusTests;
199 | sourceTree = "";
200 | };
201 | BF2118561DF5772800FF863D /* EventBus iOS */ = {
202 | isa = PBXGroup;
203 | children = (
204 | BF2118571DF5772800FF863D /* AppDelegate.swift */,
205 | BF2118591DF5772800FF863D /* ViewController.swift */,
206 | BF21185B1DF5772800FF863D /* Main.storyboard */,
207 | BF21185E1DF5772800FF863D /* Assets.xcassets */,
208 | BF2118601DF5772800FF863D /* LaunchScreen.storyboard */,
209 | BF2118631DF5772800FF863D /* Info.plist */,
210 | );
211 | path = "EventBus iOS";
212 | sourceTree = "";
213 | };
214 | BF851B7E1F5D6D240042DD59 /* Frameworks */ = {
215 | isa = PBXGroup;
216 | children = (
217 | );
218 | name = Frameworks;
219 | sourceTree = "";
220 | };
221 | BFE7A7541E64B89500F51068 /* Configs */ = {
222 | isa = PBXGroup;
223 | children = (
224 | BFE7A7551E64B89600F51068 /* Universal.xcconfig */,
225 | );
226 | name = Configs;
227 | path = EventBus.xcodeproj/Configs;
228 | sourceTree = "";
229 | };
230 | /* End PBXGroup section */
231 |
232 | /* Begin PBXHeadersBuildPhase section */
233 | BF2118321DF488DF00FF863D /* Headers */ = {
234 | isa = PBXHeadersBuildPhase;
235 | buildActionMask = 2147483647;
236 | files = (
237 | );
238 | runOnlyForDeploymentPostprocessing = 0;
239 | };
240 | /* End PBXHeadersBuildPhase section */
241 |
242 | /* Begin PBXNativeTarget section */
243 | BF2118341DF488DF00FF863D /* EventBus (Framework) */ = {
244 | isa = PBXNativeTarget;
245 | buildConfigurationList = BF2118491DF488DF00FF863D /* Build configuration list for PBXNativeTarget "EventBus (Framework)" */;
246 | buildPhases = (
247 | BF2118301DF488DF00FF863D /* Sources */,
248 | BF2118311DF488DF00FF863D /* Frameworks */,
249 | BF2118321DF488DF00FF863D /* Headers */,
250 | BF2118331DF488DF00FF863D /* Resources */,
251 | );
252 | buildRules = (
253 | );
254 | dependencies = (
255 | );
256 | name = "EventBus (Framework)";
257 | productName = EventBus;
258 | productReference = BF2118351DF488DF00FF863D /* EventBus.framework */;
259 | productType = "com.apple.product-type.framework";
260 | };
261 | BF21183D1DF488DF00FF863D /* EventBusTests */ = {
262 | isa = PBXNativeTarget;
263 | buildConfigurationList = BF21184C1DF488DF00FF863D /* Build configuration list for PBXNativeTarget "EventBusTests" */;
264 | buildPhases = (
265 | BF21183A1DF488DF00FF863D /* Sources */,
266 | BF21183B1DF488DF00FF863D /* Frameworks */,
267 | BF21183C1DF488DF00FF863D /* Resources */,
268 | );
269 | buildRules = (
270 | );
271 | dependencies = (
272 | BF2118411DF488DF00FF863D /* PBXTargetDependency */,
273 | );
274 | name = EventBusTests;
275 | productName = EventBusTests;
276 | productReference = BF21183E1DF488DF00FF863D /* EventBusTests.xctest */;
277 | productType = "com.apple.product-type.bundle.unit-test";
278 | };
279 | BF2118541DF5772800FF863D /* EventBus iOS */ = {
280 | isa = PBXNativeTarget;
281 | buildConfigurationList = BF2118661DF5772800FF863D /* Build configuration list for PBXNativeTarget "EventBus iOS" */;
282 | buildPhases = (
283 | BF2118511DF5772800FF863D /* Sources */,
284 | BF2118521DF5772800FF863D /* Frameworks */,
285 | BF2118531DF5772800FF863D /* Resources */,
286 | BF9142E81DF57F4300040556 /* Embed Frameworks */,
287 | );
288 | buildRules = (
289 | );
290 | dependencies = (
291 | BF9142E71DF57F4300040556 /* PBXTargetDependency */,
292 | );
293 | name = "EventBus iOS";
294 | productName = "EventBus iOS";
295 | productReference = BF2118551DF5772800FF863D /* EventBus iOS.app */;
296 | productType = "com.apple.product-type.application";
297 | };
298 | BF4B823D1F41ACC1009A317D /* EventBus (Static Library) */ = {
299 | isa = PBXNativeTarget;
300 | buildConfigurationList = BF4B82461F41ACC1009A317D /* Build configuration list for PBXNativeTarget "EventBus (Static Library)" */;
301 | buildPhases = (
302 | BF4B823A1F41ACC1009A317D /* Sources */,
303 | BF4B823B1F41ACC1009A317D /* Frameworks */,
304 | BF4B823C1F41ACC1009A317D /* CopyFiles */,
305 | );
306 | buildRules = (
307 | );
308 | dependencies = (
309 | );
310 | name = "EventBus (Static Library)";
311 | productName = "EventBus (Static)";
312 | productReference = BF4B823E1F41ACC1009A317D /* libEventBus.a */;
313 | productType = "com.apple.product-type.library.static";
314 | };
315 | /* End PBXNativeTarget section */
316 |
317 | /* Begin PBXProject section */
318 | BF21182C1DF488DF00FF863D /* Project object */ = {
319 | isa = PBXProject;
320 | attributes = {
321 | LastSwiftUpdateCheck = 0820;
322 | LastUpgradeCheck = 0930;
323 | ORGANIZATIONNAME = "Vincent Esche";
324 | TargetAttributes = {
325 | BF2118341DF488DF00FF863D = {
326 | CreatedOnToolsVersion = 8.2;
327 | DevelopmentTeam = GSGGFU6A2H;
328 | LastSwiftMigration = 0820;
329 | ProvisioningStyle = Manual;
330 | };
331 | BF21183D1DF488DF00FF863D = {
332 | CreatedOnToolsVersion = 8.2;
333 | DevelopmentTeam = GSGGFU6A2H;
334 | ProvisioningStyle = Automatic;
335 | };
336 | BF2118541DF5772800FF863D = {
337 | CreatedOnToolsVersion = 8.2;
338 | DevelopmentTeam = GSGGFU6A2H;
339 | ProvisioningStyle = Automatic;
340 | };
341 | BF4B823D1F41ACC1009A317D = {
342 | CreatedOnToolsVersion = 9.0;
343 | DevelopmentTeam = GSGGFU6A2H;
344 | };
345 | };
346 | };
347 | buildConfigurationList = BF21182F1DF488DF00FF863D /* Build configuration list for PBXProject "EventBus" */;
348 | compatibilityVersion = "Xcode 3.2";
349 | developmentRegion = English;
350 | hasScannedForEncodings = 0;
351 | knownRegions = (
352 | en,
353 | Base,
354 | );
355 | mainGroup = BF21182B1DF488DF00FF863D;
356 | productRefGroup = BF2118361DF488DF00FF863D /* Products */;
357 | projectDirPath = "";
358 | projectRoot = "";
359 | targets = (
360 | BF2118341DF488DF00FF863D /* EventBus (Framework) */,
361 | BF4B823D1F41ACC1009A317D /* EventBus (Static Library) */,
362 | BF21183D1DF488DF00FF863D /* EventBusTests */,
363 | BF2118541DF5772800FF863D /* EventBus iOS */,
364 | );
365 | };
366 | /* End PBXProject section */
367 |
368 | /* Begin PBXResourcesBuildPhase section */
369 | BF2118331DF488DF00FF863D /* Resources */ = {
370 | isa = PBXResourcesBuildPhase;
371 | buildActionMask = 2147483647;
372 | files = (
373 | );
374 | runOnlyForDeploymentPostprocessing = 0;
375 | };
376 | BF21183C1DF488DF00FF863D /* Resources */ = {
377 | isa = PBXResourcesBuildPhase;
378 | buildActionMask = 2147483647;
379 | files = (
380 | );
381 | runOnlyForDeploymentPostprocessing = 0;
382 | };
383 | BF2118531DF5772800FF863D /* Resources */ = {
384 | isa = PBXResourcesBuildPhase;
385 | buildActionMask = 2147483647;
386 | files = (
387 | BF2118621DF5772800FF863D /* LaunchScreen.storyboard in Resources */,
388 | BF21185F1DF5772800FF863D /* Assets.xcassets in Resources */,
389 | BF21185D1DF5772800FF863D /* Main.storyboard in Resources */,
390 | );
391 | runOnlyForDeploymentPostprocessing = 0;
392 | };
393 | /* End PBXResourcesBuildPhase section */
394 |
395 | /* Begin PBXSourcesBuildPhase section */
396 | BF2118301DF488DF00FF863D /* Sources */ = {
397 | isa = PBXSourcesBuildPhase;
398 | buildActionMask = 2147483647;
399 | files = (
400 | BFBBACF72121CEE6001F96DD /* EventChainable.swift in Sources */,
401 | BFBBACFD2121CF0E001F96DD /* ErrorHandler.swift in Sources */,
402 | BF9858582138335E0033C15D /* NSLocking+Extensions.swift in Sources */,
403 | BFBBACF92121CEF6001F96DD /* EventNotifiable.swift in Sources */,
404 | BFBBACFF2121CF27001F96DD /* LogHandler.swift in Sources */,
405 | BFF704081F5D976A00DFF413 /* EventBus.swift in Sources */,
406 | BFBBACF32121CE88001F96DD /* EventRegistrable.swift in Sources */,
407 | BFBBACFB2121CF03001F96DD /* Options.swift in Sources */,
408 | BFBBAD012121CF3C001F96DD /* Errors.swift in Sources */,
409 | BFBBACF52121CED7001F96DD /* EventSubscribable.swift in Sources */,
410 | );
411 | runOnlyForDeploymentPostprocessing = 0;
412 | };
413 | BF21183A1DF488DF00FF863D /* Sources */ = {
414 | isa = PBXSourcesBuildPhase;
415 | buildActionMask = 2147483647;
416 | files = (
417 | BF2118441DF488DF00FF863D /* EventSubscribableTests.swift in Sources */,
418 | BF851B821F5D94B00042DD59 /* EventNotifiableTests.swift in Sources */,
419 | BFF7040C1F5D981100DFF413 /* Utilities.swift in Sources */,
420 | BFF7040A1F5D97F100DFF413 /* EventChainableTests.swift in Sources */,
421 | );
422 | runOnlyForDeploymentPostprocessing = 0;
423 | };
424 | BF2118511DF5772800FF863D /* Sources */ = {
425 | isa = PBXSourcesBuildPhase;
426 | buildActionMask = 2147483647;
427 | files = (
428 | BF21185A1DF5772800FF863D /* ViewController.swift in Sources */,
429 | BF2118581DF5772800FF863D /* AppDelegate.swift in Sources */,
430 | );
431 | runOnlyForDeploymentPostprocessing = 0;
432 | };
433 | BF4B823A1F41ACC1009A317D /* Sources */ = {
434 | isa = PBXSourcesBuildPhase;
435 | buildActionMask = 2147483647;
436 | files = (
437 | BFBBAD042121D091001F96DD /* EventChainable.swift in Sources */,
438 | BFBBAD072121D091001F96DD /* ErrorHandler.swift in Sources */,
439 | BFBBAD052121D091001F96DD /* EventNotifiable.swift in Sources */,
440 | BFBBAD082121D091001F96DD /* LogHandler.swift in Sources */,
441 | BF985859213835110033C15D /* NSLocking+Extensions.swift in Sources */,
442 | BF4B82471F41AD21009A317D /* EventBus.swift in Sources */,
443 | BFBBAD022121D091001F96DD /* EventRegistrable.swift in Sources */,
444 | BFBBAD062121D091001F96DD /* Options.swift in Sources */,
445 | BFBBAD092121D091001F96DD /* Errors.swift in Sources */,
446 | BFBBAD032121D091001F96DD /* EventSubscribable.swift in Sources */,
447 | );
448 | runOnlyForDeploymentPostprocessing = 0;
449 | };
450 | /* End PBXSourcesBuildPhase section */
451 |
452 | /* Begin PBXTargetDependency section */
453 | BF2118411DF488DF00FF863D /* PBXTargetDependency */ = {
454 | isa = PBXTargetDependency;
455 | target = BF2118341DF488DF00FF863D /* EventBus (Framework) */;
456 | targetProxy = BF2118401DF488DF00FF863D /* PBXContainerItemProxy */;
457 | };
458 | BF9142E71DF57F4300040556 /* PBXTargetDependency */ = {
459 | isa = PBXTargetDependency;
460 | target = BF2118341DF488DF00FF863D /* EventBus (Framework) */;
461 | targetProxy = BF9142E61DF57F4300040556 /* PBXContainerItemProxy */;
462 | };
463 | /* End PBXTargetDependency section */
464 |
465 | /* Begin PBXVariantGroup section */
466 | BF21185B1DF5772800FF863D /* Main.storyboard */ = {
467 | isa = PBXVariantGroup;
468 | children = (
469 | BF21185C1DF5772800FF863D /* Base */,
470 | );
471 | name = Main.storyboard;
472 | sourceTree = "";
473 | };
474 | BF2118601DF5772800FF863D /* LaunchScreen.storyboard */ = {
475 | isa = PBXVariantGroup;
476 | children = (
477 | BF2118611DF5772800FF863D /* Base */,
478 | );
479 | name = LaunchScreen.storyboard;
480 | sourceTree = "";
481 | };
482 | /* End PBXVariantGroup section */
483 |
484 | /* Begin XCBuildConfiguration section */
485 | BF2118471DF488DF00FF863D /* Debug */ = {
486 | isa = XCBuildConfiguration;
487 | buildSettings = {
488 | ALWAYS_SEARCH_USER_PATHS = NO;
489 | CLANG_ANALYZER_NONNULL = YES;
490 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
491 | CLANG_CXX_LIBRARY = "libc++";
492 | CLANG_ENABLE_MODULES = YES;
493 | CLANG_ENABLE_OBJC_ARC = YES;
494 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
495 | CLANG_WARN_BOOL_CONVERSION = YES;
496 | CLANG_WARN_COMMA = YES;
497 | CLANG_WARN_CONSTANT_CONVERSION = YES;
498 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
499 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
500 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
501 | CLANG_WARN_EMPTY_BODY = YES;
502 | CLANG_WARN_ENUM_CONVERSION = YES;
503 | CLANG_WARN_INFINITE_RECURSION = YES;
504 | CLANG_WARN_INT_CONVERSION = YES;
505 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
506 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
507 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
508 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
509 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
510 | CLANG_WARN_STRICT_PROTOTYPES = YES;
511 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
512 | CLANG_WARN_UNREACHABLE_CODE = YES;
513 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
514 | COPY_PHASE_STRIP = NO;
515 | CURRENT_PROJECT_VERSION = 1;
516 | DEBUG_INFORMATION_FORMAT = dwarf;
517 | DEVELOPMENT_TEAM = GSGGFU6A2H;
518 | ENABLE_STRICT_OBJC_MSGSEND = YES;
519 | ENABLE_TESTABILITY = YES;
520 | GCC_C_LANGUAGE_STANDARD = gnu99;
521 | GCC_DYNAMIC_NO_PIC = NO;
522 | GCC_NO_COMMON_BLOCKS = YES;
523 | GCC_OPTIMIZATION_LEVEL = 0;
524 | GCC_PREPROCESSOR_DEFINITIONS = (
525 | "DEBUG=1",
526 | "$(inherited)",
527 | );
528 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
529 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
530 | GCC_WARN_UNDECLARED_SELECTOR = YES;
531 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
532 | GCC_WARN_UNUSED_FUNCTION = YES;
533 | GCC_WARN_UNUSED_VARIABLE = YES;
534 | MTL_ENABLE_DEBUG_INFO = YES;
535 | ONLY_ACTIVE_ARCH = YES;
536 | SDKROOT = iphoneos;
537 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
538 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
539 | SWIFT_VERSION = 4.0;
540 | VERSIONING_SYSTEM = "apple-generic";
541 | VERSION_INFO_PREFIX = "";
542 | };
543 | name = Debug;
544 | };
545 | BF2118481DF488DF00FF863D /* Release */ = {
546 | isa = XCBuildConfiguration;
547 | buildSettings = {
548 | ALWAYS_SEARCH_USER_PATHS = NO;
549 | CLANG_ANALYZER_NONNULL = YES;
550 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
551 | CLANG_CXX_LIBRARY = "libc++";
552 | CLANG_ENABLE_MODULES = YES;
553 | CLANG_ENABLE_OBJC_ARC = YES;
554 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
555 | CLANG_WARN_BOOL_CONVERSION = YES;
556 | CLANG_WARN_COMMA = YES;
557 | CLANG_WARN_CONSTANT_CONVERSION = YES;
558 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
559 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
560 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
561 | CLANG_WARN_EMPTY_BODY = YES;
562 | CLANG_WARN_ENUM_CONVERSION = YES;
563 | CLANG_WARN_INFINITE_RECURSION = YES;
564 | CLANG_WARN_INT_CONVERSION = YES;
565 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
566 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
567 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
568 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
569 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
570 | CLANG_WARN_STRICT_PROTOTYPES = YES;
571 | CLANG_WARN_SUSPICIOUS_MOVE = YES;
572 | CLANG_WARN_UNREACHABLE_CODE = YES;
573 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
574 | COPY_PHASE_STRIP = NO;
575 | CURRENT_PROJECT_VERSION = 1;
576 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
577 | DEVELOPMENT_TEAM = GSGGFU6A2H;
578 | ENABLE_NS_ASSERTIONS = NO;
579 | ENABLE_STRICT_OBJC_MSGSEND = YES;
580 | GCC_C_LANGUAGE_STANDARD = gnu99;
581 | GCC_NO_COMMON_BLOCKS = YES;
582 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
583 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
584 | GCC_WARN_UNDECLARED_SELECTOR = YES;
585 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
586 | GCC_WARN_UNUSED_FUNCTION = YES;
587 | GCC_WARN_UNUSED_VARIABLE = YES;
588 | MTL_ENABLE_DEBUG_INFO = NO;
589 | SDKROOT = iphoneos;
590 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
591 | SWIFT_VERSION = 4.0;
592 | VALIDATE_PRODUCT = YES;
593 | VERSIONING_SYSTEM = "apple-generic";
594 | VERSION_INFO_PREFIX = "";
595 | };
596 | name = Release;
597 | };
598 | BF21184A1DF488DF00FF863D /* Debug */ = {
599 | isa = XCBuildConfiguration;
600 | baseConfigurationReference = BFE7A7551E64B89600F51068 /* Universal.xcconfig */;
601 | buildSettings = {
602 | CLANG_ENABLE_MODULES = YES;
603 | DEFINES_MODULE = YES;
604 | DYLIB_COMPATIBILITY_VERSION = 1;
605 | DYLIB_CURRENT_VERSION = 1;
606 | DYLIB_INSTALL_NAME_BASE = "@rpath";
607 | INFOPLIST_FILE = EventBus/Info.plist;
608 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
609 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
610 | PRODUCT_BUNDLE_IDENTIFIER = com.regexident.EventBus;
611 | PRODUCT_NAME = EventBus;
612 | SKIP_INSTALL = YES;
613 | SWIFT_OPTIMIZATION_LEVEL = "-Onone";
614 | };
615 | name = Debug;
616 | };
617 | BF21184B1DF488DF00FF863D /* Release */ = {
618 | isa = XCBuildConfiguration;
619 | baseConfigurationReference = BFE7A7551E64B89600F51068 /* Universal.xcconfig */;
620 | buildSettings = {
621 | CLANG_ENABLE_MODULES = YES;
622 | DEFINES_MODULE = YES;
623 | DYLIB_COMPATIBILITY_VERSION = 1;
624 | DYLIB_CURRENT_VERSION = 1;
625 | DYLIB_INSTALL_NAME_BASE = "@rpath";
626 | INFOPLIST_FILE = EventBus/Info.plist;
627 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
628 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
629 | PRODUCT_BUNDLE_IDENTIFIER = com.regexident.EventBus;
630 | PRODUCT_NAME = EventBus;
631 | SKIP_INSTALL = YES;
632 | };
633 | name = Release;
634 | };
635 | BF21184D1DF488DF00FF863D /* Debug */ = {
636 | isa = XCBuildConfiguration;
637 | buildSettings = {
638 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
639 | INFOPLIST_FILE = EventBusTests/Info.plist;
640 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
641 | PRODUCT_BUNDLE_IDENTIFIER = com.regexident.EventBusTests;
642 | PRODUCT_NAME = "$(TARGET_NAME)";
643 | };
644 | name = Debug;
645 | };
646 | BF21184E1DF488DF00FF863D /* Release */ = {
647 | isa = XCBuildConfiguration;
648 | buildSettings = {
649 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
650 | INFOPLIST_FILE = EventBusTests/Info.plist;
651 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
652 | PRODUCT_BUNDLE_IDENTIFIER = com.regexident.EventBusTests;
653 | PRODUCT_NAME = "$(TARGET_NAME)";
654 | };
655 | name = Release;
656 | };
657 | BF2118641DF5772800FF863D /* Debug */ = {
658 | isa = XCBuildConfiguration;
659 | buildSettings = {
660 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
661 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
662 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
663 | INFOPLIST_FILE = "EventBus iOS/Info.plist";
664 | IPHONEOS_DEPLOYMENT_TARGET = 10.0;
665 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
666 | PRODUCT_BUNDLE_IDENTIFIER = "com.regexident.EventBus-iOS";
667 | PRODUCT_NAME = "$(TARGET_NAME)";
668 | };
669 | name = Debug;
670 | };
671 | BF2118651DF5772800FF863D /* Release */ = {
672 | isa = XCBuildConfiguration;
673 | buildSettings = {
674 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
675 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
676 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
677 | INFOPLIST_FILE = "EventBus iOS/Info.plist";
678 | IPHONEOS_DEPLOYMENT_TARGET = 10.0;
679 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
680 | PRODUCT_BUNDLE_IDENTIFIER = "com.regexident.EventBus-iOS";
681 | PRODUCT_NAME = "$(TARGET_NAME)";
682 | };
683 | name = Release;
684 | };
685 | BF4B82441F41ACC1009A317D /* Debug */ = {
686 | isa = XCBuildConfiguration;
687 | baseConfigurationReference = BFE7A7551E64B89600F51068 /* Universal.xcconfig */;
688 | buildSettings = {
689 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
690 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
691 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
692 | GCC_C_LANGUAGE_STANDARD = gnu11;
693 | OTHER_LDFLAGS = "-ObjC";
694 | PRODUCT_NAME = EventBus;
695 | SKIP_INSTALL = YES;
696 | };
697 | name = Debug;
698 | };
699 | BF4B82451F41ACC1009A317D /* Release */ = {
700 | isa = XCBuildConfiguration;
701 | baseConfigurationReference = BFE7A7551E64B89600F51068 /* Universal.xcconfig */;
702 | buildSettings = {
703 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE;
704 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14";
705 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
706 | GCC_C_LANGUAGE_STANDARD = gnu11;
707 | OTHER_LDFLAGS = "-ObjC";
708 | PRODUCT_NAME = EventBus;
709 | SKIP_INSTALL = YES;
710 | };
711 | name = Release;
712 | };
713 | /* End XCBuildConfiguration section */
714 |
715 | /* Begin XCConfigurationList section */
716 | BF21182F1DF488DF00FF863D /* Build configuration list for PBXProject "EventBus" */ = {
717 | isa = XCConfigurationList;
718 | buildConfigurations = (
719 | BF2118471DF488DF00FF863D /* Debug */,
720 | BF2118481DF488DF00FF863D /* Release */,
721 | );
722 | defaultConfigurationIsVisible = 0;
723 | defaultConfigurationName = Release;
724 | };
725 | BF2118491DF488DF00FF863D /* Build configuration list for PBXNativeTarget "EventBus (Framework)" */ = {
726 | isa = XCConfigurationList;
727 | buildConfigurations = (
728 | BF21184A1DF488DF00FF863D /* Debug */,
729 | BF21184B1DF488DF00FF863D /* Release */,
730 | );
731 | defaultConfigurationIsVisible = 0;
732 | defaultConfigurationName = Release;
733 | };
734 | BF21184C1DF488DF00FF863D /* Build configuration list for PBXNativeTarget "EventBusTests" */ = {
735 | isa = XCConfigurationList;
736 | buildConfigurations = (
737 | BF21184D1DF488DF00FF863D /* Debug */,
738 | BF21184E1DF488DF00FF863D /* Release */,
739 | );
740 | defaultConfigurationIsVisible = 0;
741 | defaultConfigurationName = Release;
742 | };
743 | BF2118661DF5772800FF863D /* Build configuration list for PBXNativeTarget "EventBus iOS" */ = {
744 | isa = XCConfigurationList;
745 | buildConfigurations = (
746 | BF2118641DF5772800FF863D /* Debug */,
747 | BF2118651DF5772800FF863D /* Release */,
748 | );
749 | defaultConfigurationIsVisible = 0;
750 | defaultConfigurationName = Release;
751 | };
752 | BF4B82461F41ACC1009A317D /* Build configuration list for PBXNativeTarget "EventBus (Static Library)" */ = {
753 | isa = XCConfigurationList;
754 | buildConfigurations = (
755 | BF4B82441F41ACC1009A317D /* Debug */,
756 | BF4B82451F41ACC1009A317D /* Release */,
757 | );
758 | defaultConfigurationIsVisible = 0;
759 | defaultConfigurationName = Release;
760 | };
761 | /* End XCConfigurationList section */
762 | };
763 | rootObject = BF21182C1DF488DF00FF863D /* Project object */;
764 | }
765 |
--------------------------------------------------------------------------------
/EventBus.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/EventBus.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | IDEDidComputeMac32BitWarning
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/EventBus.xcodeproj/xcshareddata/xcschemes/EventBus (Static).xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
53 |
54 |
64 |
65 |
71 |
72 |
73 |
74 |
75 |
76 |
82 |
83 |
89 |
90 |
91 |
92 |
94 |
95 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/EventBus.xcodeproj/xcshareddata/xcschemes/EventBus.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
42 |
43 |
49 |
50 |
51 |
52 |
53 |
54 |
64 |
65 |
71 |
72 |
73 |
74 |
75 |
76 |
82 |
83 |
89 |
90 |
91 |
92 |
94 |
95 |
98 |
99 |
100 |
--------------------------------------------------------------------------------
/EventBus/ErrorHandler.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import Foundation
6 |
7 | internal protocol ErrorHandler {
8 | func eventBus(_ eventBus: EventBus, receivedUnknownEvent eventType: T.Type)
9 | func eventBus(_ eventBus: EventBus, droppedUnhandledEvent eventType: T.Type)
10 | func eventBus(_ eventBus: EventBus, receivedNonClassSubscriber subscriberType: T.Type)
11 | }
12 |
13 | internal struct DefaultErrorHandler: ErrorHandler {
14 | @inline(__always)
15 | internal func eventBus(_ eventBus: EventBus, receivedUnknownEvent eventType: T.Type) {
16 | #if DEBUG
17 | typealias ErrorType = UnknownEventError
18 | let errorName = String(describing: ErrorType.self)
19 | let eventTypes = eventBus.registeredEventTypes
20 | let eventNames = eventTypes.lazy.map { "\($0)" }.joined(separator: ", ")
21 | let namesString = eventNames.isEmpty ? "" : " (e.g. \(eventNames))"
22 | print("\(eventBus): Expected event of registered type\(namesString), found: \(eventType).")
23 | print("Info: Use a \"Swift Error Breakpoint\" on type \"EventBus.\(errorName)\" to catch.")
24 | if EventBus.isStrict {
25 | do {
26 | throw ErrorType()
27 | } catch {
28 | // intentionally left blank
29 | }
30 | }
31 | #endif
32 | }
33 |
34 | @inline(__always)
35 | internal func eventBus(_ eventBus: EventBus, droppedUnhandledEvent eventType: T.Type) {
36 | #if DEBUG
37 | typealias ErrorType = UnhandledEventError
38 | let errorName = String(describing: ErrorType.self)
39 | print("\(eventBus): Event of type '\(eventType)' was not handled.")
40 | print("Info: Use a \"Swift Error Breakpoint\" on type \"EventBus.\(errorName)\" to catch.")
41 | if EventBus.isStrict {
42 | do {
43 | throw ErrorType()
44 | } catch {
45 | // intentionally left blank
46 | }
47 | }
48 | #endif
49 | }
50 |
51 | @inline(__always)
52 | internal func eventBus(_ eventBus: EventBus, receivedNonClassSubscriber subscriberType: T.Type) {
53 | #if DEBUG
54 | typealias ErrorType = InvalidSubscriberError
55 | let errorName = String(describing: ErrorType.self)
56 | print("\(eventBus): Expected class, found struct/enum: \(subscriberType).")
57 | print("Info: Use a \"Swift Error Breakpoint\" on type \"EventBus.\(errorName)\" to catch.")
58 | if EventBus.isStrict {
59 | do {
60 | throw ErrorType()
61 | } catch {
62 | // intentionally left blank
63 | }
64 | }
65 | #endif
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/EventBus/Errors.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import Foundation
6 |
7 | internal struct InvalidSubscriberError: Error {
8 | // intentionally left blank
9 | }
10 |
11 | internal struct UnknownEventError: Error {
12 | // intentionally left blank
13 | }
14 |
15 | internal struct UnhandledEventError: Error {
16 | // intentionally left blank
17 | }
18 |
--------------------------------------------------------------------------------
/EventBus/EventBus.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import Foundation
6 |
7 | public protocol EventBusProtocol: class {
8 | var options: Options { get }
9 | }
10 |
11 | /// A type-safe event bus.
12 | public class EventBus: EventBusProtocol {
13 |
14 | internal struct WeakBox: Hashable {
15 | internal weak var inner: AnyObject?
16 |
17 | internal init(_ inner: AnyObject) {
18 | self.inner = inner
19 | }
20 |
21 | internal static func == (lhs: WeakBox, rhs: WeakBox) -> Bool {
22 | return lhs.inner === rhs.inner
23 | }
24 |
25 | internal static func == (lhs: WeakBox, rhs: AnyObject) -> Bool {
26 | return lhs.inner === rhs
27 | }
28 |
29 | internal var hashValue: Int {
30 | guard let inner = self.inner else {
31 | return 0
32 | }
33 | return ObjectIdentifier(inner).hashValue
34 | }
35 | }
36 |
37 | typealias WeakSet = Set
38 |
39 | public static var isStrict: Bool = false
40 |
41 | /// A global shared event bus configured using default options.
42 | public static let shared: EventBus = EventBus()
43 |
44 | /// The event bus' configuration options.
45 | public let options: Options
46 |
47 | /// The event bus' label used for debugging.
48 | public let label: String?
49 |
50 | internal var errorHandler: ErrorHandler = DefaultErrorHandler()
51 | internal var logHandler: LogHandler = DefaultLogHandler()
52 |
53 | fileprivate var knownTypes: [ObjectIdentifier: Any] = [:]
54 |
55 | fileprivate var registered: Set = []
56 | fileprivate var subscribed: [ObjectIdentifier: WeakSet] = [:]
57 | fileprivate var chained: [ObjectIdentifier: WeakSet] = [:]
58 |
59 | fileprivate let lock: NSRecursiveLock = .init()
60 | fileprivate let notificationQueue: DispatchQueue
61 |
62 | /// Creates an event bus with a given configuration and dispatch notificationQueue.
63 | ///
64 | /// - Parameters:
65 | /// - options: the event bus' options
66 | /// - notificationQueue: the dispatch notificationQueue to notify subscribers on
67 | public init(options: Options? = nil, label: String? = nil, notificationQueue: DispatchQueue = .global()) {
68 | self.options = options ?? Options()
69 | self.label = label
70 | self.notificationQueue = notificationQueue
71 | }
72 |
73 | /// The event types the event bus is registered for.
74 | public var registeredEventTypes: [Any] {
75 | return self.registered.compactMap { self.knownTypes[$0] }
76 | }
77 |
78 | /// The event types the event bus has subscribers for.
79 | public var subscribedEventTypes: [Any] {
80 | return self.subscribed.keys.compactMap { self.knownTypes[$0] }
81 | }
82 |
83 | /// The event types the event bus has chains for.
84 | public var chainedEventTypes: [Any] {
85 | return self.chained.keys.compactMap { self.knownTypes[$0] }
86 | }
87 |
88 | @inline(__always)
89 | fileprivate func warnIfNonClass(_ subscriber: T) {
90 | // Related bug: https://bugs.swift.org/browse/SR-4420:
91 | guard !(type(of: subscriber as Any) is AnyClass) else {
92 | return
93 | }
94 | self.errorHandler.eventBus(self, receivedNonClassSubscriber: type(of: subscriber))
95 | }
96 |
97 | @inline(__always)
98 | fileprivate func warnIfUnknown(_ eventType: T.Type) {
99 | guard self.options.contains(.warnUnknown) else {
100 | return
101 | }
102 | guard !self.registered.contains(ObjectIdentifier(eventType)) else {
103 | return
104 | }
105 | self.errorHandler.eventBus(self, receivedUnknownEvent: eventType)
106 | }
107 |
108 | @inline(__always)
109 | fileprivate func warnUnhandled(_ eventType: T.Type) {
110 | guard self.options.contains(.warnUnhandled) else {
111 | return
112 | }
113 | self.errorHandler.eventBus(self, droppedUnhandledEvent: eventType)
114 | }
115 |
116 | @inline(__always)
117 | fileprivate func logEvent(_ eventType: T.Type) {
118 | guard self.options.contains(.logEvents) else {
119 | return
120 | }
121 | self.logHandler.eventBus(self, receivedEvent: eventType)
122 | }
123 |
124 | @inline(__always)
125 | fileprivate func updateSubscribers(for eventType: T.Type, closure: (inout WeakSet) -> ()) {
126 | let identifier = ObjectIdentifier(eventType)
127 | let subscribed = self.subscribed[identifier] ?? []
128 | self.subscribed[identifier] = self.update(set: subscribed, closure: closure)
129 | self.knownTypes[identifier] = String(describing: eventType)
130 | }
131 |
132 | @inline(__always)
133 | fileprivate func updateChains(for eventType: T.Type, closure: (inout WeakSet) -> ()) {
134 | let identifier = ObjectIdentifier(eventType)
135 | let chained = self.chained[identifier] ?? []
136 | self.chained[identifier] = self.update(set: chained, closure: closure)
137 | self.knownTypes[identifier] = String(describing: eventType)
138 | }
139 |
140 | @inline(__always)
141 | fileprivate func update(set: WeakSet, closure: (inout WeakSet) -> ()) -> WeakSet? {
142 | var mutableSet = set
143 | closure(&mutableSet)
144 | // Remove weak nil elements while we're at it:
145 | let filteredSet = mutableSet.filter { $0.inner != nil }
146 | return filteredSet.isEmpty ? nil : filteredSet
147 | }
148 | }
149 |
150 | extension EventBus: EventRegistrable {
151 | public func register(forEvent eventType: T.Type) {
152 | let identifier = ObjectIdentifier(eventType)
153 | self.registered.insert(identifier)
154 | self.knownTypes[identifier] = String(describing: eventType)
155 | }
156 | }
157 |
158 | extension EventBus: EventSubscribable {
159 | public func add(subscriber: T, for eventType: T.Type) {
160 | return self.add(subscriber: subscriber, for: eventType, options: self.options)
161 | }
162 |
163 | public func add(subscriber: T, for eventType: T.Type, options: Options) {
164 | self.warnIfNonClass(subscriber)
165 | if options.contains(.warnUnknown) {
166 | self.warnIfUnknown(eventType)
167 | }
168 | self.lock.with {
169 | self.updateSubscribers(for: eventType) { subscribed in
170 | subscribed.insert(WeakBox(subscriber as AnyObject))
171 | }
172 | }
173 | }
174 |
175 | public func remove(subscriber: T, for eventType: T.Type) {
176 | return self.remove(subscriber: subscriber, for: eventType, options: self.options)
177 | }
178 |
179 | public func remove(subscriber: T, for eventType: T.Type, options: Options) {
180 | self.warnIfNonClass(subscriber)
181 | if options.contains(.warnUnknown) {
182 | self.warnIfUnknown(eventType)
183 | }
184 | self.lock.with {
185 | self.updateSubscribers(for: eventType) { subscribed in
186 | while let index = subscribed.index(where: { $0 == (subscriber as AnyObject) }) {
187 | subscribed.remove(at: index)
188 | }
189 | }
190 | }
191 | }
192 |
193 | public func remove(subscriber: T) {
194 | return self.remove(subscriber: subscriber, options: self.options)
195 | }
196 |
197 | public func remove(subscriber: T, options: Options) {
198 | self.warnIfNonClass(subscriber)
199 | self.lock.with {
200 | for (identifier, subscribed) in self.subscribed {
201 | self.subscribed[identifier] = self.update(set: subscribed) { subscribed in
202 | while let index = subscribed.index(where: { $0 == (subscriber as AnyObject) }) {
203 | subscribed.remove(at: index)
204 | }
205 | }
206 | }
207 | }
208 | }
209 |
210 | public func removeAllSubscribers() {
211 | self.lock.with {
212 | self.subscribed = [:]
213 | }
214 | }
215 |
216 | internal func has(subscriber: T, for eventType: T.Type) -> Bool {
217 | return self.has(subscriber: subscriber, for: eventType, options: self.options)
218 | }
219 |
220 | internal func has(subscriber: T, for eventType: T.Type, options: Options) -> Bool {
221 | self.warnIfNonClass(subscriber)
222 | if options.contains(.warnUnknown) {
223 | self.warnIfUnknown(eventType)
224 | }
225 | return self.lock.with {
226 | guard let subscribed = self.subscribed[ObjectIdentifier(eventType)] else {
227 | return false
228 | }
229 | return subscribed.contains { $0 == (subscriber as AnyObject) }
230 | }
231 | }
232 | }
233 |
234 | extension EventBus: EventNotifiable {
235 | @discardableResult
236 | public func notify(_ eventType: T.Type, closure: @escaping (T) -> ()) -> Bool {
237 | return self.notify(eventType, options: self.options, closure: closure)
238 | }
239 |
240 | @discardableResult
241 | public func notify(_ eventType: T.Type, options: Options, closure: @escaping (T) -> ()) -> Bool {
242 | if options.contains(.warnUnknown) {
243 | self.warnIfUnknown(eventType)
244 | }
245 | self.logEvent(eventType)
246 | return self.lock.with {
247 | var handled: Int = 0
248 | let identifier = ObjectIdentifier(eventType)
249 | // Notify our direct subscribers:
250 | if let subscribers = self.subscribed[identifier] {
251 | for subscriber in subscribers.lazy.compactMap({ $0.inner as? T }) {
252 | self.notificationQueue.async {
253 | closure(subscriber)
254 | }
255 | }
256 | handled += subscribers.count
257 | }
258 | // Notify our indirect subscribers:
259 | if let chains = self.chained[identifier] {
260 | for chain in chains.lazy.compactMap({ $0.inner as? EventNotifiable }) {
261 | handled += chain.notify(eventType, closure: closure) ? 1 : 0
262 | }
263 | }
264 | if (handled == 0) && options.contains(.warnUnhandled) {
265 | self.warnUnhandled(eventType)
266 | }
267 | return handled > 0
268 | }
269 | }
270 | }
271 |
272 | extension EventBus: EventChainable {
273 | public func attach(chain: EventNotifiable, for eventType: T.Type) {
274 | return self.attach(chain: chain, for: eventType, options: self.options)
275 | }
276 |
277 | public func attach(chain: EventNotifiable, for eventType: T.Type, options: Options) {
278 | if options.contains(.warnUnknown) {
279 | self.warnIfUnknown(eventType)
280 | }
281 | self.lock.with {
282 | self.updateChains(for: eventType) { chained in
283 | chained.insert(WeakBox(chain as AnyObject))
284 | }
285 | }
286 | }
287 |
288 | public func detach(chain: EventNotifiable, for eventType: T.Type) {
289 | return self.detach(chain: chain, for: eventType, options: self.options)
290 | }
291 |
292 | public func detach(chain: EventNotifiable, for eventType: T.Type, options: Options) {
293 | if options.contains(.warnUnknown) {
294 | self.warnIfUnknown(eventType)
295 | }
296 | self.lock.with {
297 | self.updateChains(for: eventType) { chained in
298 | chained.remove(WeakBox(chain as AnyObject))
299 | }
300 | }
301 | }
302 |
303 | public func detach(chain: EventNotifiable) {
304 | self.lock.with {
305 | for (identifier, chained) in self.chained {
306 | self.chained[identifier] = self.update(set: chained) { chained in
307 | chained.remove(WeakBox(chain as AnyObject))
308 | }
309 | }
310 | }
311 | }
312 |
313 | public func detachAllChains() {
314 | self.lock.with {
315 | self.chained = [:]
316 | }
317 | }
318 |
319 | internal func has(chain: EventNotifiable, for eventType: T.Type) -> Bool {
320 | return self.has(chain: chain, for: eventType, options: self.options)
321 | }
322 |
323 | internal func has(chain: EventNotifiable, for eventType: T.Type, options: Options) -> Bool {
324 | if options.contains(.warnUnknown) {
325 | self.warnIfUnknown(eventType)
326 | }
327 | return self.lock.with {
328 | guard let chained = self.chained[ObjectIdentifier(eventType)] else {
329 | return false
330 | }
331 | return chained.contains { $0 == (chain as AnyObject) }
332 | }
333 | }
334 | }
335 |
336 | extension EventBus: CustomStringConvertible {
337 | public var description: String {
338 | var mutableSelf = self
339 | return Swift.withUnsafePointer(to: &mutableSelf) { pointer in
340 | let name = String(describing: type(of: self))
341 | let address = String(format: "%p", pointer)
342 | let label = self.label.map { " \"\($0)\"" } ?? ""
343 | return "<\(name): \(address)\(label)>"
344 | }
345 | }
346 | }
347 |
--------------------------------------------------------------------------------
/EventBus/EventChainable.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import Foundation
6 |
7 | /// A reduced type-erased interface for EventBus
8 | /// for selectively exposing its event-chaining capabilities.
9 | public protocol EventChainable: EventBusProtocol {
10 | /// Attaches a second event bus chained to the event bus.
11 | ///
12 | /// - Note:
13 | /// - Notified events on `self` get forwarded to chains attached for eventType.
14 | ///
15 | /// - Parameters
16 | /// - chain: the event bus to attach
17 | /// - eventType: the event type for which to attach the chain for
18 | ///
19 | /// ```
20 | /// let eventBus = EventBus()
21 | /// let chainedEventBus = EventBus()
22 | /// // ...
23 | /// eventBus.attach(chain: chainedEventBus, for: MyEvent.self)
24 | /// ```
25 | func attach(chain: EventNotifiable, for eventType: T.Type)
26 |
27 | /// Attaches a second event bus chained to the event bus.
28 | ///
29 | /// - Note:
30 | /// - Notified events on `self` get forwarded to chains attached for eventType.
31 | ///
32 | /// - Parameters
33 | /// - chain: the event bus to attach
34 | /// - eventType: the event type for which to attach the chain for
35 | /// - options: temporarily overwritten options for this call
36 | ///
37 | /// - SeeAlso:
38 | /// [attach(chain:for:)](EventBus.attach(chain:for:))
39 | func attach(chain: EventNotifiable, for eventType: T.Type, options: Options)
40 |
41 | /// Detaches a chained event bus from the event bus for a given event type.
42 | ///
43 | /// - Parameters
44 | /// - chain: the event bus to attach
45 | /// - eventType: the event type for which to detach the chain from
46 | ///
47 | /// ```
48 | /// let eventBus = EventBus()
49 | /// let chainedEventBus = EventBus()
50 | /// // ...
51 | /// eventBus.attach(chain: chainedEventBus, for: MyEvent.self)
52 | /// // ...
53 | /// eventBus.detach(chain: chainedEventBus, for: MyEvent.self)
54 | /// ```
55 | func detach(chain: EventNotifiable, for eventType: T.Type)
56 |
57 | /// Detaches a chained event bus from the event bus for a given event type.
58 | ///
59 | /// - Parameters
60 | /// - chain: the event bus to attach
61 | /// - eventType: the event type for which to detach the chain from
62 | /// - options: temporarily overwritten options for this call
63 | ///
64 | /// - SeeAlso:
65 | /// [detach(chain:for:)](EventBus.detach(chain:for:))
66 | func detach(chain: EventNotifiable, for eventType: T.Type, options: Options)
67 |
68 | /// Detaches a second event bus from the event bus.
69 | ///
70 | /// - Parameters
71 | /// - chain: the event bus to detach
72 | ///
73 | /// ```
74 | /// let eventBus = EventBus()
75 | /// let chainedEventBus = EventBus()
76 | /// // ...
77 | /// eventBus.attach(chain: chainedEventBus, for: MyEvent.self)
78 | /// // ...
79 | /// eventBus.detach(chain: chainedEventBus)
80 | /// ```
81 | func detach(chain: EventNotifiable)
82 |
83 | /// Detaches all attached event busses from the event bus.
84 | ///
85 | /// - Parameters
86 | /// - chain: the event bus to detach
87 | ///
88 | /// ```
89 | /// let eventBus = EventBus()
90 | /// let chainedEventBus = EventBus()
91 | /// // ...
92 | /// eventBus.attach(chain: chainedEventBus)
93 | /// // ...
94 | /// eventBus.detachAllChains()
95 | func detachAllChains()
96 | }
97 |
--------------------------------------------------------------------------------
/EventBus/EventNotifiable.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import Foundation
6 |
7 | /// A reduced type-erased interface for EventBus
8 | /// for selectively exposing its event-notification capabilities.
9 | public protocol EventNotifiable: EventBusProtocol {
10 |
11 | /// Notifies all subscribers (and chained event busses)
12 | ///
13 | /// - Parameters:
14 | /// - eventType: the event type for which to notify subscribers for
15 | /// - closure: the closure to perform on subscribers for the given event type
16 | ///
17 | /// ```
18 | /// protocol MyEvent {
19 | /// func handle(value: Int)
20 | /// }
21 | ///
22 | /// let eventBus = EventBus()
23 | /// // ...
24 | /// eventBus.add(subscriber: subscriber, for: MyEvent.self)
25 | /// // ...
26 | /// eventBus.notify(MyEvent.self) { subscriber in
27 | /// subscriber.handle(value: 42)
28 | /// }
29 | /// ```
30 | @discardableResult
31 | func notify(_ eventType: T.Type, closure: @escaping (T) -> ()) -> Bool
32 |
33 | /// Notifies all subscribers (and chained event busses)
34 | ///
35 | /// - Parameters:
36 | /// - eventType: the event type for which to notify subscribers for
37 | /// - options: temporarily overwritten options for this call
38 | /// - closure: the closure to perform on subscribers for the given event type
39 | ///
40 | /// - SeeAlso:
41 | /// [notify(_:closure:)](EventBus.notify(_:closure:))
42 | @discardableResult
43 | func notify(_ eventType: T.Type, options: Options, closure: @escaping (T) -> ()) -> Bool
44 | }
45 |
--------------------------------------------------------------------------------
/EventBus/EventRegistrable.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import Foundation
6 |
7 | /// A reduced type-erased interface for EventBus
8 | /// for selectively exposing its type-registration capabilities.
9 | public protocol EventRegistrable: EventBusProtocol {
10 | /// Registers a given event bus for a given event type.
11 | ///
12 | /// - Parameters:
13 | /// - eventType: the event type to register
14 | ///
15 | /// - Note:
16 | /// This only has an effect if the event bus
17 | /// has been initialized with the `Options.warnUnknown` flag.
18 | ///
19 | /// ```
20 | /// protocol MyEvent {
21 | /// // ...
22 | /// }
23 | ///
24 | /// let eventBus = EventBus()
25 | /// eventBus.register(forEvent: MyEvent.self)
26 | /// ```
27 | func register(forEvent eventType: T.Type)
28 | }
29 |
--------------------------------------------------------------------------------
/EventBus/EventSubscribable.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import Foundation
6 |
7 | /// A reduced type-erased interface for EventBus
8 | /// for selectively exposing its event-subscription capabilities.
9 | public protocol EventSubscribable: EventBusProtocol {
10 | /// Adds a given object to the list of subscribers of a given event type on the event bus.
11 | ///
12 | /// - Parameters:
13 | /// - subscriber: the subscriber to add to the event bus for the given event type
14 | /// - eventType: the event type to subscribe for
15 | ///
16 | /// ```
17 | /// protocol MyEvent {
18 | /// // ...
19 | /// }
20 | ///
21 | /// let eventBus = EventBus()
22 | /// // ...
23 | /// eventBus.add(subscriber: subscriber, for: MyEvent.self)
24 | /// ```
25 | func add(subscriber: T, for eventType: T.Type)
26 |
27 | /// Adds a given object to the list of subscribers of a given event type on the event bus.
28 | ///
29 | /// - Parameters:
30 | /// - subscriber: the subscriber to add to the event bus for the given event type
31 | /// - eventType: the event type to subscribe for
32 | /// - options: temporarily overwritten options for this call
33 | ///
34 | /// - SeeAlso:
35 | /// [add(subscriber:for)](EventBus.add(subscriber:for:))
36 | func add(subscriber: T, for eventType: T.Type, options: Options)
37 |
38 | /// Removes a given object from the list of subscribers of a given event type on the event bus.
39 | ///
40 | /// - Parameters:
41 | /// - subscriber: the subscriber to remove from the event bus for the given event type
42 | /// - eventType: the event type to unsubscribe from
43 | ///
44 | /// ```
45 | /// protocol MyEvent {
46 | /// // ...
47 | /// }
48 | ///
49 | /// let eventBus = EventBus()
50 | /// // ...
51 | /// eventBus.add(subscriber: subscriber, for: MyEvent.self)
52 | /// // ...
53 | /// eventBus.remove(subscriber: subscriber, for: MyEvent.self)
54 | /// ```
55 | func remove(subscriber: T, for eventType: T.Type)
56 |
57 | /// Removes a given object from the list of subscribers of a given event type on the event bus.
58 | ///
59 | /// - Parameters:
60 | /// - subscriber: the subscriber to remove from the event bus for the given event type
61 | /// - eventType: the event type to unsubscribe from
62 | /// - options: temporarily overwritten options for this call
63 | ///
64 | /// - SeeAlso:
65 | /// [remove(subscriber:for:)](EventBus.remove(subscriber:for:))
66 | func remove(subscriber: T, for eventType: T.Type, options: Options)
67 |
68 | /// Removes a given object from the list of subscribers on the event bus.
69 | ///
70 | /// - Parameters:
71 | /// - subscriber: the subscriber to remove from the event bus for all event types
72 | ///
73 | /// ```
74 | /// protocol MyEvent {
75 | /// // ...
76 | /// }
77 | ///
78 | /// let eventBus = EventBus()
79 | /// // ...
80 | /// eventBus.add(subscriber: subscriber, for: MyEvent.self)
81 | /// // ...
82 | /// eventBus.remove(subscriber: subscriber)
83 | /// ```
84 | func remove(subscriber: T)
85 |
86 | /// Removes a given object from the list of subscribers on the event bus.
87 | ///
88 | /// - Parameters:
89 | /// - subscriber: the subscriber to remove from the event bus for all event types
90 | /// - options: temporarily overwritten options for this call
91 | ///
92 | /// - SeeAlso:
93 | /// [remove(subscriber:)](EventBus.remove(subscriber:))
94 | /// ```
95 | func remove(subscriber: T, options: Options)
96 |
97 | /// Removes all objects from the list of subscribers on the event bus.
98 | ///
99 | /// ```
100 | /// protocol MyEvent {
101 | /// // ...
102 | /// }
103 | ///
104 | /// let eventBus = EventBus()
105 | /// // ...
106 | /// eventBus.add(subscriber: subscriber, for: MyEvent.self)
107 | /// // ...
108 | /// eventBus.removeAllSubscribers()
109 | /// ```
110 | func removeAllSubscribers()
111 | }
112 |
--------------------------------------------------------------------------------
/EventBus/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 | 0.4.2
19 | CFBundleVersion
20 | $(CURRENT_PROJECT_VERSION)
21 | NSPrincipalClass
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/EventBus/LogHandler.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import Foundation
6 |
7 | internal protocol LogHandler {
8 | func eventBus(_ eventBus: EventBus, receivedEvent: T.Type)
9 | }
10 |
11 | internal struct DefaultLogHandler: LogHandler {
12 | func eventBus(_ eventBus: EventBus, receivedEvent eventType: T.Type) {
13 | #if DEBUG
14 | print("\(eventBus): Received event '\(eventType)'.")
15 | #endif
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/EventBus/NSLocking+Extensions.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import Foundation
6 |
7 | protocol NSTryLocking: NSLocking {
8 | func `try`() -> Bool
9 | }
10 |
11 | extension NSLock: NSTryLocking {}
12 | extension NSConditionLock: NSTryLocking {}
13 | extension NSRecursiveLock: NSTryLocking {}
14 |
15 | extension NSLocking {
16 | public func with(closure: () -> T) -> T {
17 | self.lock()
18 | let result = closure()
19 | self.unlock()
20 | return result
21 | }
22 | }
23 |
24 | extension NSTryLocking {
25 | public func tryWith(closure: () -> T) -> T? {
26 | guard self.try() else {
27 | return nil
28 | }
29 | let result = closure()
30 | self.unlock()
31 | return result
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/EventBus/Options.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import Foundation
6 |
7 | /// Options for configuring the behavior of a given EventBus.
8 | public struct Options: OptionSet {
9 |
10 | /// See protocol `OptionSet`
11 | public let rawValue: Int
12 |
13 | /// See protocol `OptionSet`
14 | public init(rawValue: Int) {
15 | self.rawValue = rawValue
16 | }
17 |
18 | /// Print a warning whenever an event gets subscribed to or notified that has not previously
19 | /// been registered (i.e. via `eventBus.register(forEvent: MyEvent.self)`) with the event bus.
20 | ///
21 | /// - Note:
22 | /// Warning logs are only emitted if the `DEBUG` compiler flag is present.
23 | ///
24 | /// By setting `EventBus.isStrict = true` you can catch the error using
25 | /// a "Swift Error Breakpoint" on type `StrictnessError`.
26 | /// ```
27 | public static let warnUnknown = Options(rawValue: 1 << 0)
28 |
29 | /// Print a warning whenever an event gets subscribed to or notified that has not previously
30 | /// been registered (i.e. via `eventBus.register(forEvent: MyEvent.self)`) with the event bus.
31 | ///
32 | /// - Note:
33 | /// Warning logs are only emitted if the `DEBUG` compiler flag is present.
34 | ///
35 | /// By setting `EventBus.isStrict = true` you can catch the error using
36 | /// a "Swift Error Breakpoint" on type `StrictnessError`.
37 | /// ```
38 | public static let warnUnhandled = Options(rawValue: 1 << 1)
39 |
40 | /// All available warnings:
41 | /// - `.warnUnknown`
42 | /// - `.warnUnhandled`
43 | public static var allWarnings: Options {
44 | return [.warnUnknown, .warnUnhandled]
45 | }
46 |
47 | /// Print a log of emitted events for a given event bus.
48 | public static let logEvents = Options(rawValue: 1 << 2)
49 | }
50 |
--------------------------------------------------------------------------------
/EventBusTests/EventChainableTests.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import XCTest
6 |
7 | import Foundation
8 | @testable import EventBus
9 |
10 | class EventChainableTests: XCTestCase {
11 | func testAttachChain() {
12 | let rootEventBus = EventBus()
13 | let leafEventBus = EventBus()
14 |
15 | XCTAssertFalse(rootEventBus.has(chain: leafEventBus, for: FooStubable.self))
16 | rootEventBus.attach(chain: leafEventBus, for: FooStubable.self)
17 | XCTAssertTrue(rootEventBus.has(chain: leafEventBus, for: FooStubable.self))
18 | }
19 |
20 | func testDetachChain() {
21 | let rootEventBus = EventBus()
22 | let leafEventBus = EventBus()
23 | rootEventBus.attach(chain: leafEventBus, for: FooStubable.self)
24 |
25 | XCTAssertTrue(rootEventBus.has(chain: leafEventBus, for: FooStubable.self))
26 | rootEventBus.detach(chain: leafEventBus)
27 | XCTAssertFalse(rootEventBus.has(chain: leafEventBus, for: FooStubable.self))
28 | }
29 |
30 | func testDetachAllChains() {
31 | let rootEventBus = EventBus()
32 | let leafEventBusA = EventBus()
33 | let leafEventBusB = EventBus()
34 | rootEventBus.attach(chain: leafEventBusA, for: FooStubable.self)
35 | rootEventBus.attach(chain: leafEventBusB, for: FooStubable.self)
36 |
37 | XCTAssertTrue(rootEventBus.has(chain: leafEventBusA, for: FooStubable.self))
38 | XCTAssertTrue(rootEventBus.has(chain: leafEventBusB, for: FooStubable.self))
39 | rootEventBus.detachAllChains()
40 | XCTAssertFalse(rootEventBus.has(chain: leafEventBusA, for: FooStubable.self))
41 | XCTAssertFalse(rootEventBus.has(chain: leafEventBusB, for: FooStubable.self))
42 | }
43 |
44 | func testNotifyNotifiesChains() {
45 | let notifiedExpectation = self.expectation(description: "")
46 | let ignoredExpectation = self.expectation(description: "")
47 | ignoredExpectation.isInverted = true
48 |
49 | let notifiedFooMock = FooMock { _ in notifiedExpectation.fulfill() }
50 | let ignoredBarMock = BarMock { _ in ignoredExpectation.fulfill() }
51 |
52 | let rootEventBus = EventBus()
53 | let notifiedLeafEventBus = EventBus()
54 | let ignoredLeafEventBus = EventBus()
55 |
56 | rootEventBus.attach(chain: notifiedLeafEventBus, for: FooMockable.self)
57 | rootEventBus.attach(chain: ignoredLeafEventBus, for: BarMockable.self)
58 |
59 | notifiedLeafEventBus.add(subscriber: notifiedFooMock, for: FooMockable.self)
60 | ignoredLeafEventBus.add(subscriber: ignoredBarMock, for: BarMockable.self)
61 |
62 | rootEventBus.notify(FooMockable.self) { subscriber in
63 | subscriber.foo()
64 | }
65 |
66 | self.waitForExpectations(timeout: 1.0)
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/EventBusTests/EventNotifiableTests.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import XCTest
6 |
7 | import Foundation
8 | @testable import EventBus
9 |
10 | class EventNotifiableTests: XCTestCase {
11 | func testNotifyNotifiesRelatedSubscribers() {
12 | let expectation = self.expectation(description: "")
13 |
14 | let fooMock = FooMock { _ in expectation.fulfill() }
15 |
16 | let eventBus = EventBus()
17 | eventBus.add(subscriber: fooMock, for: FooMockable.self)
18 | eventBus.notify(FooMockable.self) { subscriber in
19 | subscriber.foo()
20 | }
21 |
22 | self.waitForExpectations(timeout: 1.0)
23 | }
24 |
25 | func testNotifyNotifiesIgnoresUnrelatedSubscribers() {
26 | let expectation = self.expectation(description: "")
27 | expectation.isInverted = true
28 |
29 | let fooMock = FooMock { _ in expectation.fulfill() }
30 |
31 | let eventBus = EventBus()
32 | eventBus.add(subscriber: fooMock, for: FooMockable.self)
33 | eventBus.notify(BarMockable.self) { subscriber in
34 | subscriber.bar()
35 | }
36 |
37 | self.waitForExpectations(timeout: 1.0)
38 | }
39 |
40 | func testNotifyNotifiesIgnoresUnrelatedSubscribers_() {
41 | let expectation = self.expectation(description: "")
42 |
43 | let fooBarMock = FooBarMock { event in
44 | switch event {
45 | case .foo: expectation.fulfill()
46 | case _: XCTFail("Should not have called `BarMockable` on subscriber")
47 | }
48 | }
49 |
50 | let eventBus = EventBus()
51 | eventBus.add(subscriber: fooBarMock, for: FooMockable.self)
52 | eventBus.notify(FooMockable.self) { subscriber in
53 | subscriber.foo()
54 | }
55 |
56 | self.waitForExpectations(timeout: 1.0)
57 | }
58 |
59 | func testNotifyOnUnknownEventEmitsError() {
60 | let expectation = self.expectation(description: "")
61 |
62 | let errorHandlerMock = ErrorHandlerMock { error in
63 | switch error {
64 | case .unknownEvent: expectation.fulfill()
65 | case _: XCTFail("Should not have emitted `.unknownEvent` on handler")
66 | }
67 | }
68 |
69 | let eventBus = EventBus(options: .warnUnknown)
70 | eventBus.register(forEvent: BarMockable.self)
71 | eventBus.errorHandler = errorHandlerMock
72 | eventBus.notify(FooMockable.self) { _ in }
73 |
74 | self.waitForExpectations(timeout: 1.0)
75 | }
76 |
77 | func testDropOnNotifiedEventEmitsError() {
78 | let expectation = self.expectation(description: "")
79 |
80 | let errorHandlerMock = ErrorHandlerMock { error in
81 | switch error {
82 | case .unhandledEvent: expectation.fulfill()
83 | case _: XCTFail("Should not have emitted `.unhandledEvent` on handler")
84 | }
85 | }
86 |
87 | let eventBus = EventBus(options: .warnUnhandled)
88 | eventBus.errorHandler = errorHandlerMock
89 | eventBus.notify(FooMockable.self) { _ in }
90 |
91 | self.waitForExpectations(timeout: 1.0)
92 | }
93 |
94 | func testNotifyEmitsLog() {
95 | let expectation = self.expectation(description: "")
96 |
97 | let logHandler = LogHandlerMock {
98 | expectation.fulfill()
99 | }
100 |
101 | let eventBus = EventBus(options: .logEvents)
102 | eventBus.logHandler = logHandler
103 |
104 | eventBus.notify(FooMockable.self) { subscriber in
105 | subscriber.foo()
106 | }
107 |
108 | self.waitForExpectations(timeout: 1.0)
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/EventBusTests/EventSubscribableTests.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import XCTest
6 |
7 | import Foundation
8 | @testable import EventBus
9 |
10 | class EventSubscribableTests: XCTestCase {
11 |
12 | func testAddingSubscriberWithoutRelatedSibling() {
13 | let fooStub = FooStub()
14 |
15 | let eventBus = EventBus()
16 | XCTAssertFalse(eventBus.has(subscriber: fooStub, for: FooStubable.self))
17 |
18 | eventBus.add(subscriber: fooStub, for: FooStubable.self)
19 | XCTAssertTrue(eventBus.has(subscriber: fooStub, for: FooStubable.self))
20 | }
21 |
22 | func testAddingSubscriberWithRelatedSibling() {
23 | let fooStubA = FooStub()
24 | let fooStubB = FooStub()
25 |
26 | let eventBus = EventBus()
27 | eventBus.add(subscriber: fooStubA, for: FooStubable.self)
28 | XCTAssertFalse(eventBus.has(subscriber: fooStubB, for: FooStubable.self))
29 |
30 | eventBus.add(subscriber: fooStubB, for: FooStubable.self)
31 | XCTAssertTrue(eventBus.has(subscriber: fooStubB, for: FooStubable.self))
32 | }
33 |
34 | func testAddingSubscriberWithUnrelatedSibling() {
35 | let fooStub = FooStub()
36 | let barStub = BarStub()
37 |
38 | let eventBus = EventBus()
39 | eventBus.add(subscriber: fooStub, for: FooStubable.self)
40 | XCTAssertTrue(eventBus.has(subscriber: fooStub, for: FooStubable.self))
41 | XCTAssertFalse(eventBus.has(subscriber: barStub, for: BarStubable.self))
42 |
43 | eventBus.add(subscriber: barStub, for: BarStubable.self)
44 | XCTAssertTrue(eventBus.has(subscriber: fooStub, for: FooStubable.self))
45 | XCTAssertTrue(eventBus.has(subscriber: barStub, for: BarStubable.self))
46 | }
47 |
48 | func testAddingSubscriberWithMultipleConformances() {
49 | let fooBarStub = FooBarStub()
50 |
51 | let eventBus = EventBus()
52 | eventBus.add(subscriber: fooBarStub, for: FooStubable.self)
53 | XCTAssertTrue(eventBus.has(subscriber: fooBarStub, for: FooStubable.self))
54 | XCTAssertFalse(eventBus.has(subscriber: fooBarStub, for: BarStubable.self))
55 |
56 | eventBus.add(subscriber: fooBarStub, for: BarStubable.self)
57 | XCTAssertTrue(eventBus.has(subscriber: fooBarStub, for: FooStubable.self))
58 | XCTAssertTrue(eventBus.has(subscriber: fooBarStub, for: BarStubable.self))
59 | }
60 |
61 | func testRemovingSubscriberWithoutRelatedSibling() {
62 | let fooStub = FooStub()
63 |
64 | let eventBus = EventBus()
65 | eventBus.add(subscriber: fooStub, for: FooStubable.self)
66 | XCTAssertTrue(eventBus.has(subscriber: fooStub, for: FooStubable.self))
67 |
68 | eventBus.remove(subscriber: fooStub, for: FooStubable.self)
69 | XCTAssertFalse(eventBus.has(subscriber: fooStub, for: FooStubable.self))
70 | }
71 |
72 | func testRemovingSubscriberWithRelatedSibling() {
73 | let fooStubA = FooStub()
74 | let fooStubB = FooStub()
75 |
76 | let eventBus = EventBus()
77 | eventBus.add(subscriber: fooStubA, for: FooStubable.self)
78 | eventBus.add(subscriber: fooStubB, for: FooStubable.self)
79 | XCTAssertTrue(eventBus.has(subscriber: fooStubA, for: FooStubable.self))
80 | XCTAssertTrue(eventBus.has(subscriber: fooStubB, for: FooStubable.self))
81 |
82 | eventBus.remove(subscriber: fooStubA, for: FooStubable.self)
83 | XCTAssertFalse(eventBus.has(subscriber: fooStubA, for: FooStubable.self))
84 | XCTAssertTrue(eventBus.has(subscriber: fooStubB, for: FooStubable.self))
85 | }
86 |
87 | func testRemovingSubscriberWithUnrelatedSibling() {
88 | let fooStub = FooStub()
89 | let barStub = BarStub()
90 |
91 | let eventBus = EventBus()
92 | eventBus.add(subscriber: fooStub, for: FooStubable.self)
93 | XCTAssertTrue(eventBus.has(subscriber: fooStub, for: FooStubable.self))
94 | XCTAssertFalse(eventBus.has(subscriber: barStub, for: BarStubable.self))
95 |
96 | eventBus.add(subscriber: barStub, for: BarStubable.self)
97 | XCTAssertTrue(eventBus.has(subscriber: fooStub, for: FooStubable.self))
98 | XCTAssertTrue(eventBus.has(subscriber: barStub, for: BarStubable.self))
99 | }
100 |
101 | func testRemovingSubscriberWithMultipleConformancesIndividually() {
102 | let fooBarStub = FooBarStub()
103 |
104 | let eventBus = EventBus()
105 | eventBus.add(subscriber: fooBarStub, for: FooStubable.self)
106 | eventBus.add(subscriber: fooBarStub, for: BarStubable.self)
107 | XCTAssertTrue(eventBus.has(subscriber: fooBarStub, for: FooStubable.self))
108 | XCTAssertTrue(eventBus.has(subscriber: fooBarStub, for: BarStubable.self))
109 |
110 | eventBus.remove(subscriber: fooBarStub, for: FooStubable.self)
111 | XCTAssertFalse(eventBus.has(subscriber: fooBarStub, for: FooStubable.self))
112 | XCTAssertTrue(eventBus.has(subscriber: fooBarStub, for: BarStubable.self))
113 | }
114 |
115 | func testRemovingSubscriberWithMultipleConformancesBroadly() {
116 | let fooBarStub = FooBarStub()
117 |
118 | let eventBus = EventBus()
119 | eventBus.add(subscriber: fooBarStub, for: FooStubable.self)
120 | eventBus.add(subscriber: fooBarStub, for: BarStubable.self)
121 |
122 | XCTAssertTrue(eventBus.has(subscriber: fooBarStub, for: FooStubable.self))
123 | XCTAssertTrue(eventBus.has(subscriber: fooBarStub, for: BarStubable.self))
124 |
125 | eventBus.remove(subscriber: fooBarStub)
126 | XCTAssertFalse(eventBus.has(subscriber: fooBarStub, for: FooStubable.self))
127 | XCTAssertFalse(eventBus.has(subscriber: fooBarStub, for: BarStubable.self))
128 | }
129 |
130 | func testAddingNonClassSubscriberToEventEmitsError() {
131 | let expectation = self.expectation(description: "")
132 |
133 | let errorHandlerMock = ErrorHandlerMock { error in
134 | switch error {
135 | case .invalidSubscriber: expectation.fulfill()
136 | case _: XCTFail("Should not have emitted `.invalidSubscriber` on handler")
137 | }
138 | }
139 |
140 | let eventBus = EventBus()
141 | eventBus.errorHandler = errorHandlerMock
142 | eventBus.add(subscriber: InvalidFooStub(), for: FooStubable.self)
143 |
144 | self.waitForExpectations(timeout: 1.0)
145 | }
146 |
147 | func testRemovingNonClassSubscriberFromEventEmitsError() {
148 | let expectation = self.expectation(description: "")
149 |
150 | let errorHandlerMock = ErrorHandlerMock { error in
151 | switch error {
152 | case .invalidSubscriber: expectation.fulfill()
153 | case _: XCTFail("Should not have emitted `.invalidSubscriber` on handler")
154 | }
155 | }
156 |
157 | let eventBus = EventBus()
158 | eventBus.errorHandler = errorHandlerMock
159 | eventBus.remove(subscriber: InvalidFooStub(), for: FooStubable.self)
160 |
161 | self.waitForExpectations(timeout: 1.0)
162 | }
163 |
164 | func testRemovingNonClassSubscriberEmitsError() {
165 | let expectation = self.expectation(description: "")
166 |
167 | let errorHandlerMock = ErrorHandlerMock { error in
168 | switch error {
169 | case .invalidSubscriber: expectation.fulfill()
170 | case _: XCTFail("Should not have emitted `.invalidSubscriber` on handler")
171 | }
172 | }
173 |
174 | let eventBus = EventBus()
175 | eventBus.errorHandler = errorHandlerMock
176 | eventBus.remove(subscriber: InvalidFooStub())
177 |
178 | self.waitForExpectations(timeout: 1.0)
179 | }
180 |
181 | func testSubscriptionOfUnknownEventEmitsError() {
182 | let expectation = self.expectation(description: "")
183 |
184 | let fooStub = FooStub()
185 |
186 | let errorHandlerMock = ErrorHandlerMock { error in
187 | switch error {
188 | case .unknownEvent: expectation.fulfill()
189 | case _: XCTFail("Should not have emitted `.unknownEvent` on handler")
190 | }
191 | }
192 |
193 | let eventBus = EventBus(options: .warnUnknown)
194 | eventBus.register(forEvent: BarMockable.self)
195 | eventBus.errorHandler = errorHandlerMock
196 | eventBus.add(subscriber: fooStub, for: FooStubable.self)
197 |
198 | self.waitForExpectations(timeout: 1.0)
199 | }
200 | }
201 |
--------------------------------------------------------------------------------
/EventBusTests/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 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/EventBusTests/Utilities.swift:
--------------------------------------------------------------------------------
1 | // This Source Code Form is subject to the terms of the Mozilla Public
2 | // License, v. 2.0. If a copy of the MPL was not distributed with this
3 | // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 |
5 | import Foundation
6 |
7 | @testable import EventBus
8 |
9 | protocol FooStubable {}
10 | protocol BarStubable {}
11 |
12 | class FooStub: FooStubable {}
13 | class BarStub: BarStubable {}
14 | class FooBarStub: FooStubable, BarStubable {}
15 |
16 | enum MockEvent { case foo, bar }
17 |
18 | protocol FooMockable { func foo() }
19 | protocol BarMockable { func bar() }
20 |
21 | class Mock {
22 | fileprivate let closure: (MockEvent) -> ()
23 |
24 | init(closure: ((MockEvent) -> ())? = nil) {
25 | self.closure = closure ?? { _ in }
26 | }
27 | }
28 |
29 | struct InvalidFooStub: FooStubable {}
30 |
31 | class FooMock: Mock, FooMockable {
32 | func foo() { self.closure(.foo) }
33 | }
34 |
35 | class BarMock: Mock, BarMockable {
36 | func bar() { self.closure(.bar) }
37 | }
38 |
39 | class FooBarMock: Mock, FooMockable, BarMockable {
40 | func foo() { self.closure(.foo) }
41 | func bar() { self.closure(.bar) }
42 | }
43 |
44 | enum MockError { case unknownEvent, unhandledEvent, invalidSubscriber }
45 |
46 | class ErrorHandlerMock: ErrorHandler {
47 | fileprivate let closure: (MockError) -> ()
48 |
49 | init(closure: ((MockError) -> ())? = nil) {
50 | self.closure = closure ?? { _ in }
51 | }
52 |
53 | func eventBus(_ eventBus: EventBus, receivedUnknownEvent eventType: T.Type) {
54 | self.closure(.unknownEvent)
55 | }
56 |
57 | func eventBus(_ eventBus: EventBus, droppedUnhandledEvent eventType: T.Type) {
58 | self.closure(.unhandledEvent)
59 | }
60 |
61 | func eventBus(_ eventBus: EventBus, receivedNonClassSubscriber subscriberType: T.Type) {
62 | self.closure(.invalidSubscriber)
63 | }
64 | }
65 |
66 | class LogHandlerMock: LogHandler {
67 | fileprivate let closure: () -> ()
68 |
69 | init(closure: (() -> ())? = nil) {
70 | self.closure = closure ?? { }
71 | }
72 |
73 | func eventBus(_ eventBus: EventBus, receivedEvent eventType: T.Type) {
74 | self.closure()
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/Icon.sketch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/Icon.sketch
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Mozilla Public License Version 2.0
2 | ==================================
3 |
4 | 1. Definitions
5 | --------------
6 |
7 | 1.1. "Contributor"
8 | means each individual or legal entity that creates, contributes to
9 | the creation of, or owns Covered Software.
10 |
11 | 1.2. "Contributor Version"
12 | means the combination of the Contributions of others (if any) used
13 | by a Contributor and that particular Contributor's Contribution.
14 |
15 | 1.3. "Contribution"
16 | means Covered Software of a particular Contributor.
17 |
18 | 1.4. "Covered Software"
19 | means Source Code Form to which the initial Contributor has attached
20 | the notice in Exhibit A, the Executable Form of such Source Code
21 | Form, and Modifications of such Source Code Form, in each case
22 | including portions thereof.
23 |
24 | 1.5. "Incompatible With Secondary Licenses"
25 | means
26 |
27 | (a) that the initial Contributor has attached the notice described
28 | in Exhibit B to the Covered Software; or
29 |
30 | (b) that the Covered Software was made available under the terms of
31 | version 1.1 or earlier of the License, but not also under the
32 | terms of a Secondary License.
33 |
34 | 1.6. "Executable Form"
35 | means any form of the work other than Source Code Form.
36 |
37 | 1.7. "Larger Work"
38 | means a work that combines Covered Software with other material, in
39 | a separate file or files, that is not Covered Software.
40 |
41 | 1.8. "License"
42 | means this document.
43 |
44 | 1.9. "Licensable"
45 | means having the right to grant, to the maximum extent possible,
46 | whether at the time of the initial grant or subsequently, any and
47 | all of the rights conveyed by this License.
48 |
49 | 1.10. "Modifications"
50 | means any of the following:
51 |
52 | (a) any file in Source Code Form that results from an addition to,
53 | deletion from, or modification of the contents of Covered
54 | Software; or
55 |
56 | (b) any new file in Source Code Form that contains any Covered
57 | Software.
58 |
59 | 1.11. "Patent Claims" of a Contributor
60 | means any patent claim(s), including without limitation, method,
61 | process, and apparatus claims, in any patent Licensable by such
62 | Contributor that would be infringed, but for the grant of the
63 | License, by the making, using, selling, offering for sale, having
64 | made, import, or transfer of either its Contributions or its
65 | Contributor Version.
66 |
67 | 1.12. "Secondary License"
68 | means either the GNU General Public License, Version 2.0, the GNU
69 | Lesser General Public License, Version 2.1, the GNU Affero General
70 | Public License, Version 3.0, or any later versions of those
71 | licenses.
72 |
73 | 1.13. "Source Code Form"
74 | means the form of the work preferred for making modifications.
75 |
76 | 1.14. "You" (or "Your")
77 | means an individual or a legal entity exercising rights under this
78 | License. For legal entities, "You" includes any entity that
79 | controls, is controlled by, or is under common control with You. For
80 | purposes of this definition, "control" means (a) the power, direct
81 | or indirect, to cause the direction or management of such entity,
82 | whether by contract or otherwise, or (b) ownership of more than
83 | fifty percent (50%) of the outstanding shares or beneficial
84 | ownership of such entity.
85 |
86 | 2. License Grants and Conditions
87 | --------------------------------
88 |
89 | 2.1. Grants
90 |
91 | Each Contributor hereby grants You a world-wide, royalty-free,
92 | non-exclusive license:
93 |
94 | (a) under intellectual property rights (other than patent or trademark)
95 | Licensable by such Contributor to use, reproduce, make available,
96 | modify, display, perform, distribute, and otherwise exploit its
97 | Contributions, either on an unmodified basis, with Modifications, or
98 | as part of a Larger Work; and
99 |
100 | (b) under Patent Claims of such Contributor to make, use, sell, offer
101 | for sale, have made, import, and otherwise transfer either its
102 | Contributions or its Contributor Version.
103 |
104 | 2.2. Effective Date
105 |
106 | The licenses granted in Section 2.1 with respect to any Contribution
107 | become effective for each Contribution on the date the Contributor first
108 | distributes such Contribution.
109 |
110 | 2.3. Limitations on Grant Scope
111 |
112 | The licenses granted in this Section 2 are the only rights granted under
113 | this License. No additional rights or licenses will be implied from the
114 | distribution or licensing of Covered Software under this License.
115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a
116 | Contributor:
117 |
118 | (a) for any code that a Contributor has removed from Covered Software;
119 | or
120 |
121 | (b) for infringements caused by: (i) Your and any other third party's
122 | modifications of Covered Software, or (ii) the combination of its
123 | Contributions with other software (except as part of its Contributor
124 | Version); or
125 |
126 | (c) under Patent Claims infringed by Covered Software in the absence of
127 | its Contributions.
128 |
129 | This License does not grant any rights in the trademarks, service marks,
130 | or logos of any Contributor (except as may be necessary to comply with
131 | the notice requirements in Section 3.4).
132 |
133 | 2.4. Subsequent Licenses
134 |
135 | No Contributor makes additional grants as a result of Your choice to
136 | distribute the Covered Software under a subsequent version of this
137 | License (see Section 10.2) or under the terms of a Secondary License (if
138 | permitted under the terms of Section 3.3).
139 |
140 | 2.5. Representation
141 |
142 | Each Contributor represents that the Contributor believes its
143 | Contributions are its original creation(s) or it has sufficient rights
144 | to grant the rights to its Contributions conveyed by this License.
145 |
146 | 2.6. Fair Use
147 |
148 | This License is not intended to limit any rights You have under
149 | applicable copyright doctrines of fair use, fair dealing, or other
150 | equivalents.
151 |
152 | 2.7. Conditions
153 |
154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
155 | in Section 2.1.
156 |
157 | 3. Responsibilities
158 | -------------------
159 |
160 | 3.1. Distribution of Source Form
161 |
162 | All distribution of Covered Software in Source Code Form, including any
163 | Modifications that You create or to which You contribute, must be under
164 | the terms of this License. You must inform recipients that the Source
165 | Code Form of the Covered Software is governed by the terms of this
166 | License, and how they can obtain a copy of this License. You may not
167 | attempt to alter or restrict the recipients' rights in the Source Code
168 | Form.
169 |
170 | 3.2. Distribution of Executable Form
171 |
172 | If You distribute Covered Software in Executable Form then:
173 |
174 | (a) such Covered Software must also be made available in Source Code
175 | Form, as described in Section 3.1, and You must inform recipients of
176 | the Executable Form how they can obtain a copy of such Source Code
177 | Form by reasonable means in a timely manner, at a charge no more
178 | than the cost of distribution to the recipient; and
179 |
180 | (b) You may distribute such Executable Form under the terms of this
181 | License, or sublicense it under different terms, provided that the
182 | license for the Executable Form does not attempt to limit or alter
183 | the recipients' rights in the Source Code Form under this License.
184 |
185 | 3.3. Distribution of a Larger Work
186 |
187 | You may create and distribute a Larger Work under terms of Your choice,
188 | provided that You also comply with the requirements of this License for
189 | the Covered Software. If the Larger Work is a combination of Covered
190 | Software with a work governed by one or more Secondary Licenses, and the
191 | Covered Software is not Incompatible With Secondary Licenses, this
192 | License permits You to additionally distribute such Covered Software
193 | under the terms of such Secondary License(s), so that the recipient of
194 | the Larger Work may, at their option, further distribute the Covered
195 | Software under the terms of either this License or such Secondary
196 | License(s).
197 |
198 | 3.4. Notices
199 |
200 | You may not remove or alter the substance of any license notices
201 | (including copyright notices, patent notices, disclaimers of warranty,
202 | or limitations of liability) contained within the Source Code Form of
203 | the Covered Software, except that You may alter any license notices to
204 | the extent required to remedy known factual inaccuracies.
205 |
206 | 3.5. Application of Additional Terms
207 |
208 | You may choose to offer, and to charge a fee for, warranty, support,
209 | indemnity or liability obligations to one or more recipients of Covered
210 | Software. However, You may do so only on Your own behalf, and not on
211 | behalf of any Contributor. You must make it absolutely clear that any
212 | such warranty, support, indemnity, or liability obligation is offered by
213 | You alone, and You hereby agree to indemnify every Contributor for any
214 | liability incurred by such Contributor as a result of warranty, support,
215 | indemnity or liability terms You offer. You may include additional
216 | disclaimers of warranty and limitations of liability specific to any
217 | jurisdiction.
218 |
219 | 4. Inability to Comply Due to Statute or Regulation
220 | ---------------------------------------------------
221 |
222 | If it is impossible for You to comply with any of the terms of this
223 | License with respect to some or all of the Covered Software due to
224 | statute, judicial order, or regulation then You must: (a) comply with
225 | the terms of this License to the maximum extent possible; and (b)
226 | describe the limitations and the code they affect. Such description must
227 | be placed in a text file included with all distributions of the Covered
228 | Software under this License. Except to the extent prohibited by statute
229 | or regulation, such description must be sufficiently detailed for a
230 | recipient of ordinary skill to be able to understand it.
231 |
232 | 5. Termination
233 | --------------
234 |
235 | 5.1. The rights granted under this License will terminate automatically
236 | if You fail to comply with any of its terms. However, if You become
237 | compliant, then the rights granted under this License from a particular
238 | Contributor are reinstated (a) provisionally, unless and until such
239 | Contributor explicitly and finally terminates Your grants, and (b) on an
240 | ongoing basis, if such Contributor fails to notify You of the
241 | non-compliance by some reasonable means prior to 60 days after You have
242 | come back into compliance. Moreover, Your grants from a particular
243 | Contributor are reinstated on an ongoing basis if such Contributor
244 | notifies You of the non-compliance by some reasonable means, this is the
245 | first time You have received notice of non-compliance with this License
246 | from such Contributor, and You become compliant prior to 30 days after
247 | Your receipt of the notice.
248 |
249 | 5.2. If You initiate litigation against any entity by asserting a patent
250 | infringement claim (excluding declaratory judgment actions,
251 | counter-claims, and cross-claims) alleging that a Contributor Version
252 | directly or indirectly infringes any patent, then the rights granted to
253 | You by any and all Contributors for the Covered Software under Section
254 | 2.1 of this License shall terminate.
255 |
256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all
257 | end user license agreements (excluding distributors and resellers) which
258 | have been validly granted by You or Your distributors under this License
259 | prior to termination shall survive termination.
260 |
261 | ************************************************************************
262 | * *
263 | * 6. Disclaimer of Warranty *
264 | * ------------------------- *
265 | * *
266 | * Covered Software is provided under this License on an "as is" *
267 | * basis, without warranty of any kind, either expressed, implied, or *
268 | * statutory, including, without limitation, warranties that the *
269 | * Covered Software is free of defects, merchantable, fit for a *
270 | * particular purpose or non-infringing. The entire risk as to the *
271 | * quality and performance of the Covered Software is with You. *
272 | * Should any Covered Software prove defective in any respect, You *
273 | * (not any Contributor) assume the cost of any necessary servicing, *
274 | * repair, or correction. This disclaimer of warranty constitutes an *
275 | * essential part of this License. No use of any Covered Software is *
276 | * authorized under this License except under this disclaimer. *
277 | * *
278 | ************************************************************************
279 |
280 | ************************************************************************
281 | * *
282 | * 7. Limitation of Liability *
283 | * -------------------------- *
284 | * *
285 | * Under no circumstances and under no legal theory, whether tort *
286 | * (including negligence), contract, or otherwise, shall any *
287 | * Contributor, or anyone who distributes Covered Software as *
288 | * permitted above, be liable to You for any direct, indirect, *
289 | * special, incidental, or consequential damages of any character *
290 | * including, without limitation, damages for lost profits, loss of *
291 | * goodwill, work stoppage, computer failure or malfunction, or any *
292 | * and all other commercial damages or losses, even if such party *
293 | * shall have been informed of the possibility of such damages. This *
294 | * limitation of liability shall not apply to liability for death or *
295 | * personal injury resulting from such party's negligence to the *
296 | * extent applicable law prohibits such limitation. Some *
297 | * jurisdictions do not allow the exclusion or limitation of *
298 | * incidental or consequential damages, so this exclusion and *
299 | * limitation may not apply to You. *
300 | * *
301 | ************************************************************************
302 |
303 | 8. Litigation
304 | -------------
305 |
306 | Any litigation relating to this License may be brought only in the
307 | courts of a jurisdiction where the defendant maintains its principal
308 | place of business and such litigation shall be governed by laws of that
309 | jurisdiction, without reference to its conflict-of-law provisions.
310 | Nothing in this Section shall prevent a party's ability to bring
311 | cross-claims or counter-claims.
312 |
313 | 9. Miscellaneous
314 | ----------------
315 |
316 | This License represents the complete agreement concerning the subject
317 | matter hereof. If any provision of this License is held to be
318 | unenforceable, such provision shall be reformed only to the extent
319 | necessary to make it enforceable. Any law or regulation which provides
320 | that the language of a contract shall be construed against the drafter
321 | shall not be used to construe this License against a Contributor.
322 |
323 | 10. Versions of the License
324 | ---------------------------
325 |
326 | 10.1. New Versions
327 |
328 | Mozilla Foundation is the license steward. Except as provided in Section
329 | 10.3, no one other than the license steward has the right to modify or
330 | publish new versions of this License. Each version will be given a
331 | distinguishing version number.
332 |
333 | 10.2. Effect of New Versions
334 |
335 | You may distribute the Covered Software under the terms of the version
336 | of the License under which You originally received the Covered Software,
337 | or under the terms of any subsequent version published by the license
338 | steward.
339 |
340 | 10.3. Modified Versions
341 |
342 | If you create software not governed by this License, and you want to
343 | create a new license for such software, you may create and use a
344 | modified version of this License if you rename the license and remove
345 | any references to the name of the license steward (except to note that
346 | such modified license differs from this License).
347 |
348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary
349 | Licenses
350 |
351 | If You choose to distribute Source Code Form that is Incompatible With
352 | Secondary Licenses under the terms of this version of the License, the
353 | notice described in Exhibit B of this License must be attached.
354 |
355 | Exhibit A - Source Code Form License Notice
356 | -------------------------------------------
357 |
358 | This Source Code Form is subject to the terms of the Mozilla Public
359 | License, v. 2.0. If a copy of the MPL was not distributed with this
360 | file, You can obtain one at http://mozilla.org/MPL/2.0/.
361 |
362 | If it is not possible or desirable to put the notice in a particular
363 | file, then You may include the notice in a location (such as a LICENSE
364 | file in a relevant directory) where a recipient would be likely to look
365 | for such a notice.
366 |
367 | You may add additional accurate notices of copyright ownership.
368 |
369 | Exhibit B - "Incompatible With Secondary Licenses" Notice
370 | ---------------------------------------------------------
371 |
372 | This Source Code Form is "Incompatible With Secondary Licenses", as
373 | defined by the Mozilla Public License, v. 2.0.
374 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | 
2 | # EventBus
3 |
4 | **EventBus** is a safe-by-default alternative to Cocoa's `NSNotificationCenter`. It provides a **type-safe API** that can **safely** be used from **multiple threads**. It automagically removes subscribers when they are deallocated.
5 |
6 | EventBus is to **one-to-many notifications** what a `Delegate` is to one-to-one notifications.
7 |
8 | 
9 |
10 | ## Usage
11 |
12 | ### Simple Notifications:
13 |
14 | Let's say you have a lottery that's supposed to notify all its participating players every time a new winning number is drawn:
15 |
16 | ```swift
17 | import EventBus
18 |
19 | protocol LotteryDraw {
20 | func didDraw(number: Int, in: Lottery)
21 | }
22 |
23 | class Lottery {
24 | private let eventBus = EventBus()
25 |
26 | func add(player: LottoPlayer) {
27 | self.eventBus.add(subscriber: player, for: LotteryDraw.self)
28 | }
29 |
30 | func draw() {
31 | let winningNumber = arc4random()
32 | self.eventBus.notify(LotteryDraw.self) { subscriber in
33 | subscriber.didDraw(number: Int(winningNumber), in: self)
34 | }
35 | }
36 | }
37 |
38 | class LottoPlayer : LotteryDraw {
39 | func didDraw(number: Int, in: Lottery) {
40 | if number == 123456 { print("Hooray!") }
41 | }
42 | }
43 | ```
44 |
45 | ### Complex Notifications:
46 |
47 | Nice, but what if you would like to group a set of **semantically related notifications** (such as different stages of a process) into a common protocol? No problem! Your protocol can be of **arbitrary complexity**.
48 |
49 | Consider this simple key-value-observing scenario:
50 |
51 | ```swift
52 | import EventBus
53 |
54 | protocol ValueChangeObserver {
55 | func willChangeValue(of: Publisher, from: Int, to: Int)
56 | func didChangeValue(of: Publisher, from: Int, to: Int)
57 | }
58 |
59 | class Publisher {
60 | private let eventBus = EventBus()
61 |
62 | var value: Int {
63 | willSet {
64 | self.eventBus.notify(ValueChangeObserver.self) { subscriber in
65 | subscriber.willChange(value: self.value, to: newValue)
66 | }
67 | }
68 | didSet {
69 | self.eventBus.notify(ValueChangeObserver.self) { subscriber in
70 | subscriber.didChange(value: oldValue, to: self.value)
71 | }
72 | }
73 | }
74 |
75 | func add(subscriber: ValueChangeObserver) {
76 | self.eventBus.add(subscriber: subscriber, for: ValueChangeObserver.self)
77 | }
78 | }
79 |
80 | class Subscriber : ValueChangeObserver {
81 | func willChangeValue(of: Publisher, from: Int, to: Int) {
82 | print("\(of) will change value from \(from) to \(to).")
83 | }
84 |
85 | func didChangeValue(of: Publisher, from: Int, to: Int) {
86 | print("\(of) did change value from \(from) to \(to).")
87 | }
88 | }
89 | ```
90 |
91 | ### Chaining
92 |
93 | Sometimes it is desirable to have one event bus forward a carbon copy of all of its events to a second event bus. A possible scenario would be a proxy event bus that acts as a centralized facade to an arbitrary number of internal event buses.
94 |
95 | ```swift
96 | let proxyEventBus = EventBus()
97 |
98 | let eventBus1 = EventBus()
99 | let eventBus2 = EventBus()
100 | proxyEventBus.attach(chain: eventBus1, for SomeEvent.self)
101 | proxyEventBus.attach(chain: eventBus2, for SomeEvent.self)
102 |
103 | let subscriber1 = …
104 | let subscriber2 = …
105 | eventBus1.add(subscriber: subscriber1, for: SomeEvent.self)
106 | eventBus2.add(subscriber: subscriber2, for: SomeEvent.self)
107 |
108 | proxyEventBus.notify(SomeEvent.self) { subscriber in
109 | // …
110 | }
111 |
112 | // subscriber1 & subscriber2 are getting notified
113 | ```
114 |
115 | For each event notified on either `eventBus1 ` or `eventBus2` a carbon copy will be forwarded to `proxyEventBus `.
116 |
117 | ### Encapsulation
118 |
119 | The API of EventBus is split up into these protocols:
120 |
121 | - `EventRegistrable`
122 | - `EventSubscribable`
123 | - `EventChainable`
124 | - `EventNotifiable`
125 |
126 | This enables for ergonomic safe encapsulation …
127 |
128 | ```swift
129 | public class Publisher {
130 | public var eventSubscribable: EventSubscribable {
131 | return self.eventBus
132 | }
133 |
134 | private let eventBus: EventBus = …
135 |
136 | // …
137 | }
138 | ```
139 |
140 | … preventing anybody else from issuing notifications on `Publisher`'s event bus.
141 |
142 | ## Debugging
143 |
144 | As there is no way to see from the type of `EventBus` which kind of events are to be expected to be received from it, or allowed to notified on it, **EventBus** provides optional measures for catching misuse early and as an aid in general debugging.
145 |
146 | ### Debug subscription of unregistered event types:
147 |
148 | ```swift
149 | let eventBus = EventBus(options: [.warnUnknown])
150 | eventBus.register(forEvent: FooEvent.self)
151 |
152 | // Needed to silence warning:
153 | // eventBus.register(forEvent: BarEvent.self)
154 |
155 | let subscriber = …
156 | eventBus.add(subscriber: subscriber, for: BarEvent.self)
157 |
158 | // Console:
159 | // Expected event of registered type (e.g. FooEvent), found: BarEvent.
160 | // Info: Use a "Swift Error Breakpoint" on type "EventBus.UnknownEventError" to catch.
161 | ```
162 |
163 | ### Debug notification of unregistered event types:
164 |
165 | ```swift
166 | let eventBus = EventBus(options: [.warnUnknown])
167 | eventBus.register(forEvent: FooEvent.self)
168 |
169 | // Needed to silence warning:
170 | // eventBus.register(forEvent: BarEvent.self)
171 |
172 | eventBus.notify(FooEvent.self) { subscriber in
173 | // …
174 | }
175 |
176 | // Console:
177 | // Expected event of registered type (e.g. FooEvent), found: BarEvent.
178 | // Info: Use a "Swift Error Breakpoint" on type "EventBus.UnknownEventError" to catch.
179 | ```
180 |
181 | ### Debug unhandled events:
182 |
183 | ```swift
184 | let eventBus = EventBus(options: [.warnUnhandled])
185 |
186 | // Needed to silence warning:
187 | // eventBus.add(subscriber: …, for: FooEvent.self)
188 |
189 | eventBus.notify(FooEvent.self) { subscriber in
190 | // …
191 | }
192 |
193 | // Console:
194 | // Expected event of registered type (e.g. FooEvent), found: BarEvent.
195 | // Info: Use a "Swift Error Breakpoint" on type "EventBus.UnhandledEventError" to catch.
196 | ```
197 |
198 | ## Installation
199 |
200 | The recommended way to add **EventBus** to your project is via [Carthage](https://github.com/Carthage/Carthage):
201 |
202 | github 'regexident/EventBus'
203 |
204 | Or to add **EventBus** to your project is via [CocoaPods](https://cocoapods.org):
205 |
206 | pod 'Swift-EventBus'
207 |
208 | ## License
209 |
210 | **EventBus** is available under a **MPL-2 license**. See the `LICENSE` file for more info.
211 |
--------------------------------------------------------------------------------
/Swift-EventBus.podspec:
--------------------------------------------------------------------------------
1 | Pod::Spec.new do |s|
2 | s.name = 'Swift-EventBus'
3 | s.version = '0.4.2'
4 | s.summary = 'A safe-by-default pure Swift notification center.'
5 |
6 | s.description = <<-DESC
7 | A safe-by-default pure Swift alternative to Cocoa's `NSNotificationCenter`.
8 | DESC
9 |
10 | s.homepage = 'https://github.com/regexident/EventBus'
11 | s.license = { :type => 'BSD-3', :file => 'LICENSE' }
12 | s.author = { 'regexident' => 'regexident@gmail.com' }
13 | s.source = { :git => 'https://github.com/regexident/EventBus.git', :tag => s.version.to_s }
14 |
15 | s.ios.deployment_target = '9.0'
16 | s.osx.deployment_target = '10.11'
17 | s.watchos.deployment_target = '3.0'
18 | s.tvos.deployment_target = '10.0'
19 |
20 | s.source_files = 'EventBus/**/*.swift'
21 | end
22 |
--------------------------------------------------------------------------------
/jumbotron.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/jumbotron.png
--------------------------------------------------------------------------------
/screencast.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/regexident/EventBus/7ae8f64e56878b4e834c94276202d20db3daff9a/screencast.gif
--------------------------------------------------------------------------------