├── .gitignore ├── LICENSE ├── ObservableEvent.podspec ├── ObservableEvent.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── ObservableEvent ├── Disposable.swift ├── DisposeBag.swift ├── EventDisposable.swift ├── Info.plist ├── ObservableEvent.h ├── ObservableEvent.swift └── Property.swift ├── ObservableEventTests ├── DisposableTests.swift ├── Info.plist ├── ObservableEventTests.swift └── PropertyTests.swift └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata 19 | 20 | ## Other 21 | *.xccheckout 22 | *.moved-aside 23 | *.xcuserstate 24 | *.xcscmblueprint 25 | 26 | ## Obj-C/Swift specific 27 | *.hmap 28 | *.ipa 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/screenshots 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /ObservableEvent.podspec: -------------------------------------------------------------------------------- 1 | # 2 | 3 | Pod::Spec.new do |s| 4 | 5 | # ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 6 | # 7 | 8 | s.name = "ObservableEvent" 9 | s.version = "2.0.0" 10 | s.summary = "A simple observer pattern implemented in Swift." 11 | 12 | s.description = "ObservableEvent is a simple observer pattern implemented in Swift." 13 | 14 | s.homepage = "https://github.com/tkier/ObservableEvent" 15 | 16 | 17 | # ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 18 | # 19 | 20 | s.license = "Apache License, Version 2.0" 21 | 22 | 23 | # ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 24 | # 25 | 26 | s.author = { "Tom Kier" => "tom@endlesswavesoftware.com" } 27 | 28 | # ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 29 | # 30 | 31 | s.platform = :ios, "9.0" 32 | 33 | 34 | # ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 35 | # 36 | 37 | s.source = { :git => "https://github.com/tkier/ObservableEvent.git", :tag => "#{s.version}" } 38 | 39 | 40 | # ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― # 41 | # 42 | # CocoaPods is smart about how it includes source code. For source files 43 | # giving a folder will include any swift, h, m, mm, c & cpp files. 44 | # For header files it will include any header in the folder. 45 | # Not including the public_header_files will make all headers public. 46 | # 47 | 48 | s.source_files = "ObservableEvent/*.{h,swift}" 49 | 50 | end 51 | -------------------------------------------------------------------------------- /ObservableEvent.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E2095C771CF0F79D00AD8BCD /* ObservableEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2095C761CF0F79D00AD8BCD /* ObservableEvent.swift */; }; 11 | E29CDB301EB2A43E007C3E8E /* Property.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29CDB2F1EB2A43E007C3E8E /* Property.swift */; }; 12 | E29CDB321EB2A7D4007C3E8E /* Disposable.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29CDB311EB2A7D4007C3E8E /* Disposable.swift */; }; 13 | E29CDB341EB2A8D6007C3E8E /* DisposeBag.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29CDB331EB2A8D6007C3E8E /* DisposeBag.swift */; }; 14 | E29CDB361EB2ABDF007C3E8E /* PropertyTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E29CDB351EB2ABDF007C3E8E /* PropertyTests.swift */; }; 15 | E2D927E41EB302B800806E93 /* DisposableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2D927E31EB302B800806E93 /* DisposableTests.swift */; }; 16 | E2D927E61EB5495800806E93 /* EventDisposable.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2D927E51EB5495800806E93 /* EventDisposable.swift */; }; 17 | E2EBB95F1CE7E94300D6B7E4 /* ObservableEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = E2EBB95E1CE7E94300D6B7E4 /* ObservableEvent.h */; settings = {ATTRIBUTES = (Public, ); }; }; 18 | E2EBB9661CE7E94300D6B7E4 /* ObservableEvent.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E2EBB95B1CE7E94300D6B7E4 /* ObservableEvent.framework */; }; 19 | E2EBB96B1CE7E94300D6B7E4 /* ObservableEventTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2EBB96A1CE7E94300D6B7E4 /* ObservableEventTests.swift */; }; 20 | /* End PBXBuildFile section */ 21 | 22 | /* Begin PBXContainerItemProxy section */ 23 | E2EBB9671CE7E94300D6B7E4 /* PBXContainerItemProxy */ = { 24 | isa = PBXContainerItemProxy; 25 | containerPortal = E2EBB9521CE7E94300D6B7E4 /* Project object */; 26 | proxyType = 1; 27 | remoteGlobalIDString = E2EBB95A1CE7E94300D6B7E4; 28 | remoteInfo = ObservableEvent; 29 | }; 30 | /* End PBXContainerItemProxy section */ 31 | 32 | /* Begin PBXFileReference section */ 33 | E2095C761CF0F79D00AD8BCD /* ObservableEvent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObservableEvent.swift; sourceTree = ""; }; 34 | E29CDB2F1EB2A43E007C3E8E /* Property.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Property.swift; sourceTree = ""; }; 35 | E29CDB311EB2A7D4007C3E8E /* Disposable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Disposable.swift; sourceTree = ""; }; 36 | E29CDB331EB2A8D6007C3E8E /* DisposeBag.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DisposeBag.swift; sourceTree = ""; }; 37 | E29CDB351EB2ABDF007C3E8E /* PropertyTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PropertyTests.swift; sourceTree = ""; }; 38 | E2D927E31EB302B800806E93 /* DisposableTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DisposableTests.swift; sourceTree = ""; }; 39 | E2D927E51EB5495800806E93 /* EventDisposable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventDisposable.swift; sourceTree = ""; }; 40 | E2EBB95B1CE7E94300D6B7E4 /* ObservableEvent.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ObservableEvent.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 41 | E2EBB95E1CE7E94300D6B7E4 /* ObservableEvent.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ObservableEvent.h; sourceTree = ""; }; 42 | E2EBB9601CE7E94300D6B7E4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43 | E2EBB9651CE7E94300D6B7E4 /* ObservableEventTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = ObservableEventTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 44 | E2EBB96A1CE7E94300D6B7E4 /* ObservableEventTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObservableEventTests.swift; sourceTree = ""; }; 45 | E2EBB96C1CE7E94300D6B7E4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 46 | /* End PBXFileReference section */ 47 | 48 | /* Begin PBXFrameworksBuildPhase section */ 49 | E2EBB9571CE7E94300D6B7E4 /* Frameworks */ = { 50 | isa = PBXFrameworksBuildPhase; 51 | buildActionMask = 2147483647; 52 | files = ( 53 | ); 54 | runOnlyForDeploymentPostprocessing = 0; 55 | }; 56 | E2EBB9621CE7E94300D6B7E4 /* Frameworks */ = { 57 | isa = PBXFrameworksBuildPhase; 58 | buildActionMask = 2147483647; 59 | files = ( 60 | E2EBB9661CE7E94300D6B7E4 /* ObservableEvent.framework in Frameworks */, 61 | ); 62 | runOnlyForDeploymentPostprocessing = 0; 63 | }; 64 | /* End PBXFrameworksBuildPhase section */ 65 | 66 | /* Begin PBXGroup section */ 67 | E2EBB9511CE7E94300D6B7E4 = { 68 | isa = PBXGroup; 69 | children = ( 70 | E2EBB95D1CE7E94300D6B7E4 /* ObservableEvent */, 71 | E2EBB9691CE7E94300D6B7E4 /* ObservableEventTests */, 72 | E2EBB95C1CE7E94300D6B7E4 /* Products */, 73 | ); 74 | sourceTree = ""; 75 | }; 76 | E2EBB95C1CE7E94300D6B7E4 /* Products */ = { 77 | isa = PBXGroup; 78 | children = ( 79 | E2EBB95B1CE7E94300D6B7E4 /* ObservableEvent.framework */, 80 | E2EBB9651CE7E94300D6B7E4 /* ObservableEventTests.xctest */, 81 | ); 82 | name = Products; 83 | sourceTree = ""; 84 | }; 85 | E2EBB95D1CE7E94300D6B7E4 /* ObservableEvent */ = { 86 | isa = PBXGroup; 87 | children = ( 88 | E2EBB95E1CE7E94300D6B7E4 /* ObservableEvent.h */, 89 | E2EBB9601CE7E94300D6B7E4 /* Info.plist */, 90 | E2095C761CF0F79D00AD8BCD /* ObservableEvent.swift */, 91 | E29CDB2F1EB2A43E007C3E8E /* Property.swift */, 92 | E29CDB311EB2A7D4007C3E8E /* Disposable.swift */, 93 | E2D927E51EB5495800806E93 /* EventDisposable.swift */, 94 | E29CDB331EB2A8D6007C3E8E /* DisposeBag.swift */, 95 | ); 96 | path = ObservableEvent; 97 | sourceTree = ""; 98 | }; 99 | E2EBB9691CE7E94300D6B7E4 /* ObservableEventTests */ = { 100 | isa = PBXGroup; 101 | children = ( 102 | E2EBB96A1CE7E94300D6B7E4 /* ObservableEventTests.swift */, 103 | E29CDB351EB2ABDF007C3E8E /* PropertyTests.swift */, 104 | E2D927E31EB302B800806E93 /* DisposableTests.swift */, 105 | E2EBB96C1CE7E94300D6B7E4 /* Info.plist */, 106 | ); 107 | path = ObservableEventTests; 108 | sourceTree = ""; 109 | }; 110 | /* End PBXGroup section */ 111 | 112 | /* Begin PBXHeadersBuildPhase section */ 113 | E2EBB9581CE7E94300D6B7E4 /* Headers */ = { 114 | isa = PBXHeadersBuildPhase; 115 | buildActionMask = 2147483647; 116 | files = ( 117 | E2EBB95F1CE7E94300D6B7E4 /* ObservableEvent.h in Headers */, 118 | ); 119 | runOnlyForDeploymentPostprocessing = 0; 120 | }; 121 | /* End PBXHeadersBuildPhase section */ 122 | 123 | /* Begin PBXNativeTarget section */ 124 | E2EBB95A1CE7E94300D6B7E4 /* ObservableEvent */ = { 125 | isa = PBXNativeTarget; 126 | buildConfigurationList = E2EBB96F1CE7E94300D6B7E4 /* Build configuration list for PBXNativeTarget "ObservableEvent" */; 127 | buildPhases = ( 128 | E2EBB9561CE7E94300D6B7E4 /* Sources */, 129 | E2EBB9571CE7E94300D6B7E4 /* Frameworks */, 130 | E2EBB9581CE7E94300D6B7E4 /* Headers */, 131 | E2EBB9591CE7E94300D6B7E4 /* Resources */, 132 | ); 133 | buildRules = ( 134 | ); 135 | dependencies = ( 136 | ); 137 | name = ObservableEvent; 138 | productName = ObservableEvent; 139 | productReference = E2EBB95B1CE7E94300D6B7E4 /* ObservableEvent.framework */; 140 | productType = "com.apple.product-type.framework"; 141 | }; 142 | E2EBB9641CE7E94300D6B7E4 /* ObservableEventTests */ = { 143 | isa = PBXNativeTarget; 144 | buildConfigurationList = E2EBB9721CE7E94300D6B7E4 /* Build configuration list for PBXNativeTarget "ObservableEventTests" */; 145 | buildPhases = ( 146 | E2EBB9611CE7E94300D6B7E4 /* Sources */, 147 | E2EBB9621CE7E94300D6B7E4 /* Frameworks */, 148 | E2EBB9631CE7E94300D6B7E4 /* Resources */, 149 | ); 150 | buildRules = ( 151 | ); 152 | dependencies = ( 153 | E2EBB9681CE7E94300D6B7E4 /* PBXTargetDependency */, 154 | ); 155 | name = ObservableEventTests; 156 | productName = ObservableEventTests; 157 | productReference = E2EBB9651CE7E94300D6B7E4 /* ObservableEventTests.xctest */; 158 | productType = "com.apple.product-type.bundle.unit-test"; 159 | }; 160 | /* End PBXNativeTarget section */ 161 | 162 | /* Begin PBXProject section */ 163 | E2EBB9521CE7E94300D6B7E4 /* Project object */ = { 164 | isa = PBXProject; 165 | attributes = { 166 | LastSwiftUpdateCheck = 0730; 167 | LastUpgradeCheck = 0730; 168 | ORGANIZATIONNAME = "Endless Wave Software"; 169 | TargetAttributes = { 170 | E2EBB95A1CE7E94300D6B7E4 = { 171 | CreatedOnToolsVersion = 7.3; 172 | DevelopmentTeam = PNK557J4EE; 173 | LastSwiftMigration = 0800; 174 | }; 175 | E2EBB9641CE7E94300D6B7E4 = { 176 | CreatedOnToolsVersion = 7.3; 177 | DevelopmentTeam = PNK557J4EE; 178 | LastSwiftMigration = 0800; 179 | }; 180 | }; 181 | }; 182 | buildConfigurationList = E2EBB9551CE7E94300D6B7E4 /* Build configuration list for PBXProject "ObservableEvent" */; 183 | compatibilityVersion = "Xcode 3.2"; 184 | developmentRegion = English; 185 | hasScannedForEncodings = 0; 186 | knownRegions = ( 187 | en, 188 | ); 189 | mainGroup = E2EBB9511CE7E94300D6B7E4; 190 | productRefGroup = E2EBB95C1CE7E94300D6B7E4 /* Products */; 191 | projectDirPath = ""; 192 | projectRoot = ""; 193 | targets = ( 194 | E2EBB95A1CE7E94300D6B7E4 /* ObservableEvent */, 195 | E2EBB9641CE7E94300D6B7E4 /* ObservableEventTests */, 196 | ); 197 | }; 198 | /* End PBXProject section */ 199 | 200 | /* Begin PBXResourcesBuildPhase section */ 201 | E2EBB9591CE7E94300D6B7E4 /* Resources */ = { 202 | isa = PBXResourcesBuildPhase; 203 | buildActionMask = 2147483647; 204 | files = ( 205 | ); 206 | runOnlyForDeploymentPostprocessing = 0; 207 | }; 208 | E2EBB9631CE7E94300D6B7E4 /* Resources */ = { 209 | isa = PBXResourcesBuildPhase; 210 | buildActionMask = 2147483647; 211 | files = ( 212 | ); 213 | runOnlyForDeploymentPostprocessing = 0; 214 | }; 215 | /* End PBXResourcesBuildPhase section */ 216 | 217 | /* Begin PBXSourcesBuildPhase section */ 218 | E2EBB9561CE7E94300D6B7E4 /* Sources */ = { 219 | isa = PBXSourcesBuildPhase; 220 | buildActionMask = 2147483647; 221 | files = ( 222 | E29CDB341EB2A8D6007C3E8E /* DisposeBag.swift in Sources */, 223 | E2D927E61EB5495800806E93 /* EventDisposable.swift in Sources */, 224 | E29CDB301EB2A43E007C3E8E /* Property.swift in Sources */, 225 | E29CDB321EB2A7D4007C3E8E /* Disposable.swift in Sources */, 226 | E2095C771CF0F79D00AD8BCD /* ObservableEvent.swift in Sources */, 227 | ); 228 | runOnlyForDeploymentPostprocessing = 0; 229 | }; 230 | E2EBB9611CE7E94300D6B7E4 /* Sources */ = { 231 | isa = PBXSourcesBuildPhase; 232 | buildActionMask = 2147483647; 233 | files = ( 234 | E29CDB361EB2ABDF007C3E8E /* PropertyTests.swift in Sources */, 235 | E2D927E41EB302B800806E93 /* DisposableTests.swift in Sources */, 236 | E2EBB96B1CE7E94300D6B7E4 /* ObservableEventTests.swift in Sources */, 237 | ); 238 | runOnlyForDeploymentPostprocessing = 0; 239 | }; 240 | /* End PBXSourcesBuildPhase section */ 241 | 242 | /* Begin PBXTargetDependency section */ 243 | E2EBB9681CE7E94300D6B7E4 /* PBXTargetDependency */ = { 244 | isa = PBXTargetDependency; 245 | target = E2EBB95A1CE7E94300D6B7E4 /* ObservableEvent */; 246 | targetProxy = E2EBB9671CE7E94300D6B7E4 /* PBXContainerItemProxy */; 247 | }; 248 | /* End PBXTargetDependency section */ 249 | 250 | /* Begin XCBuildConfiguration section */ 251 | E2EBB96D1CE7E94300D6B7E4 /* Debug */ = { 252 | isa = XCBuildConfiguration; 253 | buildSettings = { 254 | ALWAYS_SEARCH_USER_PATHS = NO; 255 | CLANG_ANALYZER_NONNULL = YES; 256 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 257 | CLANG_CXX_LIBRARY = "libc++"; 258 | CLANG_ENABLE_MODULES = YES; 259 | CLANG_ENABLE_OBJC_ARC = YES; 260 | CLANG_WARN_BOOL_CONVERSION = YES; 261 | CLANG_WARN_CONSTANT_CONVERSION = YES; 262 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 263 | CLANG_WARN_EMPTY_BODY = YES; 264 | CLANG_WARN_ENUM_CONVERSION = YES; 265 | CLANG_WARN_INT_CONVERSION = YES; 266 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 267 | CLANG_WARN_UNREACHABLE_CODE = YES; 268 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 269 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 270 | COPY_PHASE_STRIP = NO; 271 | CURRENT_PROJECT_VERSION = 1; 272 | DEBUG_INFORMATION_FORMAT = dwarf; 273 | ENABLE_STRICT_OBJC_MSGSEND = YES; 274 | ENABLE_TESTABILITY = YES; 275 | GCC_C_LANGUAGE_STANDARD = gnu99; 276 | GCC_DYNAMIC_NO_PIC = NO; 277 | GCC_NO_COMMON_BLOCKS = YES; 278 | GCC_OPTIMIZATION_LEVEL = 0; 279 | GCC_PREPROCESSOR_DEFINITIONS = ( 280 | "DEBUG=1", 281 | "$(inherited)", 282 | ); 283 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 284 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 285 | GCC_WARN_UNDECLARED_SELECTOR = YES; 286 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 287 | GCC_WARN_UNUSED_FUNCTION = YES; 288 | GCC_WARN_UNUSED_VARIABLE = YES; 289 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 290 | MTL_ENABLE_DEBUG_INFO = YES; 291 | ONLY_ACTIVE_ARCH = YES; 292 | SDKROOT = iphoneos; 293 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 294 | TARGETED_DEVICE_FAMILY = "1,2"; 295 | VERSIONING_SYSTEM = "apple-generic"; 296 | VERSION_INFO_PREFIX = ""; 297 | }; 298 | name = Debug; 299 | }; 300 | E2EBB96E1CE7E94300D6B7E4 /* Release */ = { 301 | isa = XCBuildConfiguration; 302 | buildSettings = { 303 | ALWAYS_SEARCH_USER_PATHS = NO; 304 | CLANG_ANALYZER_NONNULL = YES; 305 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 306 | CLANG_CXX_LIBRARY = "libc++"; 307 | CLANG_ENABLE_MODULES = YES; 308 | CLANG_ENABLE_OBJC_ARC = YES; 309 | CLANG_WARN_BOOL_CONVERSION = YES; 310 | CLANG_WARN_CONSTANT_CONVERSION = YES; 311 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 312 | CLANG_WARN_EMPTY_BODY = YES; 313 | CLANG_WARN_ENUM_CONVERSION = YES; 314 | CLANG_WARN_INT_CONVERSION = YES; 315 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 316 | CLANG_WARN_UNREACHABLE_CODE = YES; 317 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 318 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 319 | COPY_PHASE_STRIP = NO; 320 | CURRENT_PROJECT_VERSION = 1; 321 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 322 | ENABLE_NS_ASSERTIONS = NO; 323 | ENABLE_STRICT_OBJC_MSGSEND = YES; 324 | GCC_C_LANGUAGE_STANDARD = gnu99; 325 | GCC_NO_COMMON_BLOCKS = YES; 326 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 327 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 328 | GCC_WARN_UNDECLARED_SELECTOR = YES; 329 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 330 | GCC_WARN_UNUSED_FUNCTION = YES; 331 | GCC_WARN_UNUSED_VARIABLE = YES; 332 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 333 | MTL_ENABLE_DEBUG_INFO = NO; 334 | SDKROOT = iphoneos; 335 | TARGETED_DEVICE_FAMILY = "1,2"; 336 | VALIDATE_PRODUCT = YES; 337 | VERSIONING_SYSTEM = "apple-generic"; 338 | VERSION_INFO_PREFIX = ""; 339 | }; 340 | name = Release; 341 | }; 342 | E2EBB9701CE7E94300D6B7E4 /* Debug */ = { 343 | isa = XCBuildConfiguration; 344 | buildSettings = { 345 | CLANG_ENABLE_MODULES = YES; 346 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 347 | DEFINES_MODULE = YES; 348 | DEVELOPMENT_TEAM = PNK557J4EE; 349 | DYLIB_COMPATIBILITY_VERSION = 1; 350 | DYLIB_CURRENT_VERSION = 1; 351 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 352 | INFOPLIST_FILE = ObservableEvent/Info.plist; 353 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 354 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 355 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 356 | PRODUCT_BUNDLE_IDENTIFIER = com.endlesswavesoftware.ObservableEvent; 357 | PRODUCT_NAME = "$(TARGET_NAME)"; 358 | SKIP_INSTALL = YES; 359 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 360 | SWIFT_VERSION = 3.0; 361 | }; 362 | name = Debug; 363 | }; 364 | E2EBB9711CE7E94300D6B7E4 /* Release */ = { 365 | isa = XCBuildConfiguration; 366 | buildSettings = { 367 | CLANG_ENABLE_MODULES = YES; 368 | DEFINES_MODULE = YES; 369 | DEVELOPMENT_TEAM = PNK557J4EE; 370 | DYLIB_COMPATIBILITY_VERSION = 1; 371 | DYLIB_CURRENT_VERSION = 1; 372 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 373 | INFOPLIST_FILE = ObservableEvent/Info.plist; 374 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 375 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 376 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 377 | PRODUCT_BUNDLE_IDENTIFIER = com.endlesswavesoftware.ObservableEvent; 378 | PRODUCT_NAME = "$(TARGET_NAME)"; 379 | SKIP_INSTALL = YES; 380 | SWIFT_VERSION = 3.0; 381 | }; 382 | name = Release; 383 | }; 384 | E2EBB9731CE7E94300D6B7E4 /* Debug */ = { 385 | isa = XCBuildConfiguration; 386 | buildSettings = { 387 | DEVELOPMENT_TEAM = PNK557J4EE; 388 | INFOPLIST_FILE = ObservableEventTests/Info.plist; 389 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 390 | PRODUCT_BUNDLE_IDENTIFIER = com.endlesswavesoftware.ObservableEventTests; 391 | PRODUCT_NAME = "$(TARGET_NAME)"; 392 | SWIFT_VERSION = 3.0; 393 | }; 394 | name = Debug; 395 | }; 396 | E2EBB9741CE7E94300D6B7E4 /* Release */ = { 397 | isa = XCBuildConfiguration; 398 | buildSettings = { 399 | DEVELOPMENT_TEAM = PNK557J4EE; 400 | INFOPLIST_FILE = ObservableEventTests/Info.plist; 401 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 402 | PRODUCT_BUNDLE_IDENTIFIER = com.endlesswavesoftware.ObservableEventTests; 403 | PRODUCT_NAME = "$(TARGET_NAME)"; 404 | SWIFT_VERSION = 3.0; 405 | }; 406 | name = Release; 407 | }; 408 | /* End XCBuildConfiguration section */ 409 | 410 | /* Begin XCConfigurationList section */ 411 | E2EBB9551CE7E94300D6B7E4 /* Build configuration list for PBXProject "ObservableEvent" */ = { 412 | isa = XCConfigurationList; 413 | buildConfigurations = ( 414 | E2EBB96D1CE7E94300D6B7E4 /* Debug */, 415 | E2EBB96E1CE7E94300D6B7E4 /* Release */, 416 | ); 417 | defaultConfigurationIsVisible = 0; 418 | defaultConfigurationName = Release; 419 | }; 420 | E2EBB96F1CE7E94300D6B7E4 /* Build configuration list for PBXNativeTarget "ObservableEvent" */ = { 421 | isa = XCConfigurationList; 422 | buildConfigurations = ( 423 | E2EBB9701CE7E94300D6B7E4 /* Debug */, 424 | E2EBB9711CE7E94300D6B7E4 /* Release */, 425 | ); 426 | defaultConfigurationIsVisible = 0; 427 | defaultConfigurationName = Release; 428 | }; 429 | E2EBB9721CE7E94300D6B7E4 /* Build configuration list for PBXNativeTarget "ObservableEventTests" */ = { 430 | isa = XCConfigurationList; 431 | buildConfigurations = ( 432 | E2EBB9731CE7E94300D6B7E4 /* Debug */, 433 | E2EBB9741CE7E94300D6B7E4 /* Release */, 434 | ); 435 | defaultConfigurationIsVisible = 0; 436 | defaultConfigurationName = Release; 437 | }; 438 | /* End XCConfigurationList section */ 439 | }; 440 | rootObject = E2EBB9521CE7E94300D6B7E4 /* Project object */; 441 | } 442 | -------------------------------------------------------------------------------- /ObservableEvent.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ObservableEvent/Disposable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Disposable.swift 3 | // ObservableEvent 4 | // 5 | // Created by Tom Kier on 4/27/17. 6 | // 7 | // Copyright 2017 Endless Wave Software LLC 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | 21 | import Foundation 22 | 23 | /// Implements a disposable observer 24 | public protocol Disposable { 25 | 26 | /** 27 | 28 | Disposes the associated observer, causing the observer to be removed. 29 | */ 30 | func dispose() 31 | 32 | /** 33 | 34 | Adds this Disposable to a DisposableBag so that it will be disposed when the bag is disposed or deallocated. 35 | 36 | - Parameter disposeBag: The DisposeBag to add itself to. 37 | */ 38 | func disposeWith(_ disposeBag: DisposeBag) 39 | 40 | } 41 | -------------------------------------------------------------------------------- /ObservableEvent/DisposeBag.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DisposeBag.swift 3 | // ObservableEvent 4 | // 5 | // Created by Tom Kier on 4/27/17. 6 | // 7 | // Copyright 2017 Endless Wave Software LLC 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | 21 | import Foundation 22 | 23 | /// Implements a bag that contains Disopable objects. It will dispose all its contents when it is deinitialized, or when its dispose() method is called. 24 | open class DisposeBag { 25 | 26 | private var disposables: [Disposable] = [] 27 | 28 | public init() {} 29 | 30 | deinit { 31 | dispose() 32 | } 33 | 34 | /** 35 | 36 | Adds a Disposable to the bag. 37 | 38 | - Parameter disposable: The Disposable to add. 39 | */ 40 | public func addDisposable(_ disposable: Disposable) { 41 | disposables.append(disposable) 42 | } 43 | 44 | /** 45 | 46 | Calls dispose on Disposables in the bag, and then empties itself. 47 | */ 48 | public func dispose() { 49 | for disposable in disposables { 50 | disposable.dispose() 51 | } 52 | disposables.removeAll() 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /ObservableEvent/EventDisposable.swift: -------------------------------------------------------------------------------- 1 | // 2 | // EventDisposable.swift 3 | // ObservableEvent 4 | // 5 | // Created by Tom Kier on 4/29/17. 6 | // 7 | // Copyright 2017 Endless Wave Software LLC 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | 21 | import Foundation 22 | 23 | internal typealias RemoveObserver = () -> Void 24 | 25 | internal class EventDisposable: Disposable { 26 | 27 | private var removeObserver: RemoveObserver? 28 | 29 | internal init(_ removeObserver: @escaping RemoveObserver) { 30 | self.removeObserver = removeObserver 31 | } 32 | 33 | public func dispose() { 34 | removeObserver?() 35 | removeObserver = nil 36 | } 37 | 38 | public func disposeWith(_ disposeBag: DisposeBag) { 39 | disposeBag.addDisposable(self) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /ObservableEvent/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /ObservableEvent/ObservableEvent.h: -------------------------------------------------------------------------------- 1 | // 2 | // ObservableEvent.h 3 | // ObservableEvent 4 | // 5 | // Created by Tom Kier on 5/14/16. 6 | // 7 | // Copyright 2016 Endless Wave Software LLC 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | 21 | #import 22 | 23 | //! Project version number for ObservableEvent. 24 | FOUNDATION_EXPORT double ObservableEventVersionNumber; 25 | 26 | //! Project version string for ObservableEvent. 27 | FOUNDATION_EXPORT const unsigned char ObservableEventVersionString[]; 28 | 29 | // In this header, you should import all the public headers of your framework using statements like #import 30 | 31 | 32 | -------------------------------------------------------------------------------- /ObservableEvent/ObservableEvent.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ObservableEvent.swift 3 | // ObservableEvent 4 | // 5 | // Created by Tom Kier on 5/14/16. 6 | // 7 | // Copyright 2016 Endless Wave Software LLC 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | 21 | import Foundation 22 | 23 | /// Implements a simple observer pattern 24 | open class ObservableEvent { 25 | 26 | fileprivate var observers: [(Int, (T) -> Void)] = [] 27 | fileprivate var nextId = ObservableEvent.idGenerator() 28 | 29 | public init() {} 30 | 31 | /** 32 | 33 | Adds an observer to this event. 34 | 35 | - Parameter observer: A closure that will be called when notifyObservers is called. 36 | 37 | - Returns: A Disposable that will remove the observer when it is disposed. 38 | 39 | */ 40 | open func observe(_ observer: @escaping (T) -> Void) -> Disposable { 41 | let id = nextId() 42 | observers.append((id, observer)) 43 | 44 | return EventDisposable({ [weak self] in 45 | self?.removeObserverForId(id) 46 | }) 47 | } 48 | 49 | /** 50 | 51 | Notify all observers of this event. 52 | 53 | - Parameter data: A data value to pass to the observers. 54 | 55 | */ 56 | open func notifyObservers(_ data: T) { 57 | for observer in observers { 58 | observer.1(data) 59 | } 60 | } 61 | 62 | fileprivate func removeObserverForId(_ id:Int) { 63 | observers = observers.filter { $0.0 != id } 64 | } 65 | 66 | fileprivate static func idGenerator() -> () -> Int { 67 | var lastId = 0 68 | return { 69 | lastId += 1 70 | return lastId 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /ObservableEvent/Property.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Property.swift 3 | // ObservableEvent 4 | // 5 | // Created by Tom Kier on 4/27/17. 6 | // 7 | // Copyright 2017 Endless Wave Software LLC 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | 21 | import Foundation 22 | 23 | /// Implements an observable property that notifies observers whenever its value is changed. 24 | open class Property { 25 | 26 | /** 27 | 28 | The value of the property. When the value is set, all observers are called. 29 | */ 30 | public var value: T { 31 | didSet { 32 | observableEvent.notifyObservers(value) 33 | } 34 | } 35 | private var observableEvent: ObservableEvent 36 | 37 | /** 38 | 39 | Initializes a property and sets its initial value. 40 | 41 | - Parameter intialValue: The initial value of the property. 42 | */ 43 | public init(_ intialValue: T) { 44 | value = intialValue 45 | observableEvent = ObservableEvent() 46 | } 47 | 48 | /** 49 | 50 | Adds an observer to this property. 51 | 52 | - Parameter observer: A closure that will be called when the observer is intially added and anytime the property value is changed. 53 | 54 | - Returns: A Disposable that will remove the observer when it is disposed. 55 | 56 | */ 57 | public func observe(_ observer: @escaping (T) -> Void) -> Disposable { 58 | observer(value) 59 | return observableEvent.observe(observer) 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ObservableEventTests/DisposableTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DisposableTests.swift 3 | // ObservableEvent 4 | // 5 | // Created by Tom Kier on 4/27/17. 6 | // 7 | // Copyright 2017 Endless Wave Software LLC 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | 21 | import XCTest 22 | @testable import ObservableEvent 23 | 24 | class DisposableTests: XCTestCase { 25 | 26 | override func setUp() { 27 | super.setUp() 28 | // Put setup code here. This method is called before the invocation of each test method in the class. 29 | } 30 | 31 | override func tearDown() { 32 | // Put teardown code here. This method is called after the invocation of each test method in the class. 33 | super.tearDown() 34 | } 35 | 36 | func testDisposable() { 37 | 38 | let property = Property(1) 39 | 40 | var result = 0 41 | let disposable = property.observe { value in 42 | result = value 43 | } 44 | XCTAssert(result == 1) 45 | 46 | disposable.dispose() 47 | XCTAssert(result == 1) 48 | 49 | property.value = 2 50 | XCTAssert(result == 1) 51 | } 52 | 53 | func testDisposableBag() { 54 | 55 | let bag = DisposeBag() 56 | let property = Property(1) 57 | 58 | var result = 0 59 | property.observe { value in 60 | result = value 61 | }.disposeWith(bag) 62 | XCTAssert(result == 1) 63 | 64 | property.value = 2 65 | XCTAssert(result == 2) 66 | 67 | bag.dispose() 68 | 69 | property.value = 3 70 | XCTAssert(result == 2) 71 | } 72 | 73 | func testDisposableBagDisposeOnDeinit() { 74 | 75 | var result = 0 76 | let property = Property(1) 77 | 78 | let disposable = property.observe { value in 79 | result = value 80 | } 81 | XCTAssert(result == 1) 82 | 83 | if true { 84 | let bag = DisposeBag() 85 | 86 | bag.addDisposable(disposable) 87 | 88 | property.value = 2 89 | XCTAssert(result == 2) 90 | } 91 | 92 | property.value = 3 93 | XCTAssert(result == 2) 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /ObservableEventTests/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 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /ObservableEventTests/ObservableEventTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ObservableEventTests.swift 3 | // ObservableEventTests 4 | // 5 | // Created by Tom Kier on 5/14/16. 6 | // 7 | // Copyright 2016 Endless Wave Software LLC 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | 21 | import XCTest 22 | @testable import ObservableEvent 23 | 24 | class ObservableEventTests: XCTestCase { 25 | 26 | var eventValue :String? 27 | 28 | func testNotify() { 29 | 30 | let event = ObservableEvent() 31 | 32 | var observerdValue = 0 33 | 34 | let disposable = event.observe { value in 35 | observerdValue = value 36 | } 37 | 38 | XCTAssert(observerdValue == 0) 39 | 40 | event.notifyObservers(1) 41 | XCTAssert(observerdValue == 1) 42 | 43 | event.notifyObservers(2) 44 | XCTAssert(observerdValue == 2) 45 | 46 | disposable.dispose() 47 | 48 | event.notifyObservers(3) 49 | XCTAssert(observerdValue == 2) 50 | } 51 | 52 | func testMultipleObservers() { 53 | 54 | let event = ObservableEvent() 55 | 56 | var observerdValue1 = 0 57 | var observerdValue2 = 0 58 | 59 | let disposable1 = event.observe { value in 60 | observerdValue1 = value 61 | } 62 | let disposable2 = event.observe { value in 63 | observerdValue2 = value 64 | } 65 | 66 | XCTAssert(observerdValue1 == 0) 67 | XCTAssert(observerdValue2 == 0) 68 | 69 | event.notifyObservers(1) 70 | XCTAssert(observerdValue1 == 1) 71 | XCTAssert(observerdValue2 == 1) 72 | 73 | event.notifyObservers(2) 74 | XCTAssert(observerdValue1 == 2) 75 | XCTAssert(observerdValue2 == 2) 76 | 77 | disposable1.dispose() 78 | 79 | event.notifyObservers(3) 80 | XCTAssert(observerdValue1 == 2) 81 | XCTAssert(observerdValue2 == 3) 82 | 83 | disposable2.dispose() 84 | 85 | event.notifyObservers(4) 86 | XCTAssert(observerdValue1 == 2) 87 | XCTAssert(observerdValue2 == 3) 88 | } 89 | 90 | func testVoidEvent() { 91 | 92 | let event = ObservableEvent() 93 | 94 | var eventFired = false 95 | 96 | let disposable = event.observe { 97 | eventFired = true 98 | } 99 | 100 | XCTAssertFalse(eventFired) 101 | 102 | event.notifyObservers() 103 | 104 | XCTAssertTrue(eventFired) 105 | 106 | disposable.dispose() 107 | } 108 | 109 | func testTupleEvent() { 110 | 111 | let event = ObservableEvent<(Int, Int)>() 112 | 113 | var result1 = 0 114 | var result2 = 0 115 | 116 | let disposable = event.observe { a, b in 117 | result1 = a 118 | result2 = b 119 | } 120 | 121 | XCTAssert(result1 == 0) 122 | XCTAssert(result2 == 0) 123 | 124 | event.notifyObservers((1, 2)) 125 | 126 | XCTAssert(result1 == 1) 127 | XCTAssert(result2 == 2) 128 | 129 | disposable.dispose() 130 | } 131 | 132 | func testObserverMethod() { 133 | 134 | let event = ObservableEvent() 135 | 136 | eventValue = nil 137 | 138 | let disposable = event.observe(eventChanged) 139 | 140 | XCTAssertNil(eventValue) 141 | 142 | event.notifyObservers("It Works!!") 143 | 144 | XCTAssert(eventValue == "It Works!!") 145 | 146 | disposable.dispose() 147 | } 148 | 149 | func eventChanged(value:String) { 150 | eventValue = value 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /ObservableEventTests/PropertyTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PropertyTests.swift 3 | // ObservableEvent 4 | // 5 | // Created by Tom Kier on 4/27/17. 6 | // 7 | // Copyright 2017 Endless Wave Software LLC 8 | // 9 | // Licensed under the Apache License, Version 2.0 (the "License"); 10 | // you may not use this file except in compliance with the License. 11 | // You may obtain a copy of the License at 12 | // 13 | // http://www.apache.org/licenses/LICENSE-2.0 14 | // 15 | // Unless required by applicable law or agreed to in writing, software 16 | // distributed under the License is distributed on an "AS IS" BASIS, 17 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | // See the License for the specific language governing permissions and 19 | // limitations under the License. 20 | 21 | import XCTest 22 | @testable import ObservableEvent 23 | 24 | class PropertyTests: XCTestCase { 25 | 26 | override func setUp() { 27 | super.setUp() 28 | // Put setup code here. This method is called before the invocation of each test method in the class. 29 | } 30 | 31 | override func tearDown() { 32 | // Put teardown code here. This method is called after the invocation of each test method in the class. 33 | super.tearDown() 34 | } 35 | 36 | func testProperty() { 37 | 38 | let property: Property 39 | 40 | property = Property(1) 41 | XCTAssert(property.value == 1) 42 | 43 | property.value = 2 44 | XCTAssert(property.value == 2) 45 | } 46 | 47 | func testPropertySubscription() { 48 | 49 | let property = Property("hello") 50 | XCTAssert(property.value == "hello") 51 | 52 | var result = "" 53 | let disposable = property.observe { (value) in 54 | result = value 55 | } 56 | XCTAssert(result == "hello") 57 | 58 | property.value = "testing" 59 | XCTAssert(result == "testing") 60 | 61 | disposable.dispose() 62 | 63 | property.value = "more testing" 64 | XCTAssert(result == "testing") 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ObservableEvent 2 | 3 | ## About 4 | 5 | ObservableEvent is a simple observer pattern implemented in Swift. For more information on why ObservableEvent was created and thinking behind it, see the blog bost: [Observable Events in Swift](http://endlesswavesoftware.com/blog/observable-events-in-swift/) 6 | 7 | ## Installation 8 | The ObservableEvent framework can be installed using CocoaPods. Add the following line to your project pod file and the run "pod install". 9 | 10 | ```text 11 | pod 'ObservableEvent', '~> 2.0.0' 12 | ``` 13 | 14 | ## Using ObservableEvent 15 | 16 | #### Creating an ObservableEvent 17 | 18 | To create an observable event create an instances of the ObservableEvent class. ObservableEvents are typed with the data type that is being observered. When notifiying oberservers a value of that type will be sent with the notification. 19 | 20 | For example, a game might have an observable event that would notify observers whenever the score changes. Since the score is an Int type creating the ObservableEvent would look like: 21 | 22 | ```swift 23 | let scoreChangedEvent = ObservableEvent() 24 | ``` 25 | 26 | It is possible to create an ObservableEvent that can notifiy observers with multiple values. Simply use a tuple for the generic type. For example: 27 | 28 | ```swift 29 | let scoreChangedEvent = ObservableEvent<(score:Int, isHighScore:Bool)>() 30 | ``` 31 | 32 | It is even possible to create ObeservableEvents without any type. Simply use Void for the generic type: 33 | 34 | ```swift 35 | let myEvent = ObservableEvent() 36 | ``` 37 | 38 | #### Notifying Observers 39 | 40 | To notify all oberservers of the event call the event's notifyObservers method passing a value for the event. In our game score example we can notify all observers that the score changed and pass the new score to the observers as follows: 41 | 42 | ```swift 43 | scoreChangedEvent.notifyObservers(1000) 44 | ``` 45 | 46 | If you are using a tuple as the genric type: 47 | 48 | ```swift 49 | scoreChangedEvent.notifyObservers((score:25, isHighScore:false)) 50 | ``` 51 | 52 | Or with no generic type: 53 | 54 | ```swift 55 | myEvent.notifyObservers() 56 | ``` 57 | 58 | #### Adding an Observer 59 | 60 | To add an observer for an event call the event's observe method, passing a closure that will be called when notifyObservers is called. The observe call returns a Disposable object that can be used to remove the observer (see below for more details). 61 | 62 | In our game score event example, an observer might look like: 63 | 64 | ```swift 65 | let scoreDisposable = scoreChangeEvent.observe { score in 66 | // process new score 67 | } 68 | ``` 69 | 70 | Or if the event had a tuple type: 71 | 72 | ```swift 73 | let scoreDisposable = scoreChangeEvent.observe { score, isHighScore in 74 | // process new score and isHighScore 75 | } 76 | ``` 77 | 78 | Or if the event is using Void for the generic type: 79 | 80 | ```swift 81 | let myEventDispsoable = myEvent.observe { 82 | // event fired, do something 83 | } 84 | ``` 85 | 86 | #### Removing an Observer 87 | 88 | To remove an observer call the dispose method on the Disposable object that was returned by the observe method. For example: 89 | 90 | ```swift 91 | scoreDisposable.dispose() 92 | ``` 93 | 94 | If you are observing several events and have multiple Disoposable objects, it is more convient to use a DisposeBag to remove all the observers at once. First create an instance of DisposeBag. Then when adding an observer, add the returned disposble to the bag by calling the diposeWith(bag) method. For example: 95 | 96 | ```swift 97 | let bag = DisposeBag() 98 | 99 | scoreChangeEvent.observe { score, isHighScore in 100 | // process new score and isHighScore 101 | }.disposeWith(bag) 102 | 103 | myEvent.observe { 104 | // event fired, do something 105 | }.disposeWith(bag) 106 | ``` 107 | 108 | Now when the bag is deallocated all its contents will automatically be disposed causing all the observers to be removed. You can also explicitly call the dispose() method on the bag itself to dispose all of its contents. 109 | 110 | ## Property 111 | ObservableEvents are often used to provide change notifications for when a specific variable changes. It would typically look something like: 112 | 113 | ```swift 114 | var score: Int = 0 { 115 | didSet { 116 | scoreChangedEvent.notififyObservers(score) 117 | } 118 | } 119 | let scoreChangedEvent = ObservableEvent() 120 | ``` 121 | 122 | The Property class provides a convient way to implement this pattern by combining the variable instance and the observerable event into a single class. 123 | 124 | #### Using Properties 125 | 126 | To create a property, create an instance of the Property class, passing the properties initial value to the intialaizer. The above score example can be implementing using a Property as follows: 127 | 128 | ```swift 129 | var score: Property(0) 130 | ``` 131 | 132 | To access the value of the Property use its value property: 133 | 134 | ```swift 135 | let currentScore = score.value 136 | ``` 137 | 138 | You set the property's value by assigning to its value property. Whenever a property's value is set, it will automatically notify all observers. 139 | 140 | ```swift 141 | score.value = currentScore + 100 142 | ``` 143 | 144 | To add an observer to a property call its observe method. It works identical to the observe method on ObservableEvent, passing in a closure and returning a Disposable: 145 | 146 | 147 | ```swift 148 | score.observe { score in 149 | // process the score 150 | }.disposeWith(bag) 151 | ``` 152 | 153 | An important note about properties... the observer closure will be called with the current value of the property as soon as the observe method is called. This means that property observers are called with the current value of the property and any future values. 154 | 155 | ## License 156 | Copyright 2017 Endless Wave Software LLC 157 | 158 | Licensed under the Apache License, Version 2.0 (the "License"); 159 | you may not use this file except in compliance with the License. 160 | You may obtain a copy of the License at 161 | 162 | http://www.apache.org/licenses/LICENSE-2.0 163 | 164 | Unless required by applicable law or agreed to in writing, software 165 | distributed under the License is distributed on an "AS IS" BASIS, 166 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 167 | See the License for the specific language governing permissions and 168 | limitations under the License. 169 | --------------------------------------------------------------------------------