From 55a68cfcab5c386a1511d6c956385a611c3dbd30 Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Tue, 26 Apr 2016 21:33:25 +0900 Subject: [PATCH 01/16] Avoid compilation errors when built with DEVELOPMENT-SNAPSHOT-2016-04-12-a --- Sources/EventSource.swift | 6 +++--- Sources/Listener.swift | 4 ++-- Sources/ListenerStore.swift | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Sources/EventSource.swift b/Sources/EventSource.swift index a8d09b6..1cb7e68 100644 --- a/Sources/EventSource.swift +++ b/Sources/EventSource.swift @@ -50,13 +50,13 @@ public class EventSource { /// - Parameter handler: A closure which handles events. /// - Returns: A listener object. /// - public func listen(handler: T -> Void) -> Listener { + public func listen(_ handler: T -> Void) -> Listener { let listener = Listener(eventSource: self, handler: handler) listeners.append(listener) return listener } - func unlisten(listener: Listener) { + func unlisten(_ listener: Listener) { if let pool = unlistenPools.last { pool.listeners.append(listener) } else { @@ -71,7 +71,7 @@ public class EventSource { /// /// - Parameter value: An event value. /// - public func fire(value: T) { + public func fire(_ value: T) { unlistenPools.append(UnlistenPool()) listeners.forEach { listener in diff --git a/Sources/Listener.swift b/Sources/Listener.swift index bad271e..5c4ffbb 100644 --- a/Sources/Listener.swift +++ b/Sources/Listener.swift @@ -46,10 +46,10 @@ public class Listener: Unlistenable, Equatable { init(eventSource: EventSource, handler: Handler) { self.eventSource = eventSource - self.handler = handler; + self.handler = handler } - func handleEvent(value: T) { + func handleEvent(_ value: T) { handler(value) } diff --git a/Sources/ListenerStore.swift b/Sources/ListenerStore.swift index 3d86ff8..3bf4d49 100644 --- a/Sources/ListenerStore.swift +++ b/Sources/ListenerStore.swift @@ -45,7 +45,7 @@ public class ListenerStore { /// /// - Parameter listener: A listener which will be added to this store. /// - public func add(listener: Unlistenable) { + public func add(_ listener: Unlistenable) { items.append(listener) } From 072f6b98a808e3e6209c70112d18e32e07cdc0a9 Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Tue, 26 Apr 2016 21:34:41 +0900 Subject: [PATCH 02/16] Add `Listener.add(to:)` --- Sources/Listener.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Sources/Listener.swift b/Sources/Listener.swift index 5c4ffbb..39ebf2a 100644 --- a/Sources/Listener.swift +++ b/Sources/Listener.swift @@ -70,6 +70,17 @@ public class Listener: Unlistenable, Equatable { public func addToStore(listenerStore: ListenerStore) { listenerStore.add(self) } + + /// + /// Adds this object to specified listener store. + /// Calling this method is equivalent to calling `ListenerStore.add(_:)` with this object as a parameter. + /// + /// - Parameter listenerStore: A listener store to which this object is added. + /// - SeeAlso: `ListenerStore.add(_:)` + /// + public func add(to listenerStore: ListenerStore) { + listenerStore.add(self) + } } /// From 50d815995a76426ae36c3972af9a9af0579e9eef Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Tue, 26 Apr 2016 21:43:44 +0900 Subject: [PATCH 03/16] Add a test case for `ListenerStore.add(to:)` --- Eventitic/EventiticTests/EventiticTests.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Eventitic/EventiticTests/EventiticTests.swift b/Eventitic/EventiticTests/EventiticTests.swift index d17c70f..f76c9dd 100644 --- a/Eventitic/EventiticTests/EventiticTests.swift +++ b/Eventitic/EventiticTests/EventiticTests.swift @@ -160,11 +160,11 @@ class EventiticTests: XCTestCase { source.listen { value in values1.append("#1: \(value)") - }.addToStore(listenerStore) + }.addToStore(listenerStore) source.listen { value in values2.append("#2: \(value)") - }.addToStore(listenerStore) + }.add(to: listenerStore) source.fire("foo") From b078dfe0261148d93599927e39a315d8e82f5d60 Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Tue, 26 Apr 2016 21:49:59 +0900 Subject: [PATCH 04/16] Use `ListenerStore.add(to:)` rather than `ListenerStore.addToStore()` in example --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 35243ef..e69430f 100644 --- a/README.md +++ b/README.md @@ -38,15 +38,15 @@ let source2 = EventSource() // listen source1.listen { message in print("listener 1: \(message)") -}.addToStore(store) +}.add(to: store) source1.listen { message in print("listener 2: \(message)") -}.addToStore(store) +}.add(to: store) source2.listen { value in print("listener 3: \(value)") -}.addToStore(store) +}.add(to: store) // dispatch source1.fire("foo") From 8130cf96aa778a67c152c8c860130b583d7f019d Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Tue, 26 Apr 2016 22:16:50 +0900 Subject: [PATCH 05/16] Temporarily allow warnings --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 916ca07..c0b34ec 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,4 +11,4 @@ osx_image: xcode7.3 # - pod install --project-directory=Example script: - set -o pipefail && xcodebuild test -project Eventitic/Eventitic.xcodeproj -scheme Eventitic_iOS -destination 'platform=iOS Simulator,name=iPhone 5s' ONLY_ACTIVE_ARCH=NO | xcpretty -- pod lib lint +- pod lib lint --allow-warnings From c1a1b725e54e6b5b64a31a015f77ef8c048e430a Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Thu, 8 Sep 2016 20:32:58 +0900 Subject: [PATCH 06/16] Updated to Swift 3 --- Eventitic/Eventitic.xcodeproj/project.pbxproj | 33 ++++++++------ .../xcschemes/Eventitic_OSX.xcscheme | 2 +- .../xcschemes/Eventitic_iOS.xcscheme | 2 +- .../xcschemes/Eventitic_tvOS.xcscheme | 2 +- .../xcschemes/Eventitic_watchOS.xcscheme | 2 +- Eventitic/EventiticTests/EventiticTests.swift | 23 +++++++--- Sources/Compatible.swift | 44 ------------------- Sources/EventSource.swift | 14 +++--- Sources/Listener.swift | 17 +++---- Sources/ListenerStore.swift | 8 ++-- 10 files changed, 61 insertions(+), 86 deletions(-) delete mode 100644 Sources/Compatible.swift diff --git a/Eventitic/Eventitic.xcodeproj/project.pbxproj b/Eventitic/Eventitic.xcodeproj/project.pbxproj index 77180e1..6988593 100644 --- a/Eventitic/Eventitic.xcodeproj/project.pbxproj +++ b/Eventitic/Eventitic.xcodeproj/project.pbxproj @@ -10,13 +10,9 @@ 50AF3AF71CC6FC3C0042F81C /* Eventitic.h in Headers */ = {isa = PBXBuildFile; fileRef = 50AF3AF61CC6FC3C0042F81C /* Eventitic.h */; settings = {ATTRIBUTES = (Public, ); }; }; 50AF3AFE1CC6FC3C0042F81C /* Eventitic.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 50AF3AF31CC6FC3C0042F81C /* Eventitic.framework */; }; 50AF3B031CC6FC3C0042F81C /* EventiticTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50AF3B021CC6FC3C0042F81C /* EventiticTests.swift */; }; - 50AF3B131CC6FD890042F81C /* Compatible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50AF3B0F1CC6FD890042F81C /* Compatible.swift */; }; 50AF3B141CC6FD890042F81C /* EventSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50AF3B101CC6FD890042F81C /* EventSource.swift */; }; 50AF3B151CC6FD890042F81C /* Listener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50AF3B111CC6FD890042F81C /* Listener.swift */; }; 50AF3B161CC6FD890042F81C /* ListenerStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50AF3B121CC6FD890042F81C /* ListenerStore.swift */; }; - 50E0DB761CC7CB8E00441694 /* Compatible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50AF3B0F1CC6FD890042F81C /* Compatible.swift */; }; - 50E0DB771CC7CB8E00441694 /* Compatible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50AF3B0F1CC6FD890042F81C /* Compatible.swift */; }; - 50E0DB781CC7CB8F00441694 /* Compatible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50AF3B0F1CC6FD890042F81C /* Compatible.swift */; }; 50E0DB791CC7CB9200441694 /* EventSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50AF3B101CC6FD890042F81C /* EventSource.swift */; }; 50E0DB7A1CC7CB9300441694 /* EventSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50AF3B101CC6FD890042F81C /* EventSource.swift */; }; 50E0DB7B1CC7CB9300441694 /* EventSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = 50AF3B101CC6FD890042F81C /* EventSource.swift */; }; @@ -49,7 +45,6 @@ 50AF3AFD1CC6FC3C0042F81C /* EventiticTests_iOS.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = EventiticTests_iOS.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 50AF3B021CC6FC3C0042F81C /* EventiticTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EventiticTests.swift; sourceTree = ""; }; 50AF3B041CC6FC3C0042F81C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 50AF3B0F1CC6FD890042F81C /* Compatible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Compatible.swift; sourceTree = ""; }; 50AF3B101CC6FD890042F81C /* EventSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventSource.swift; sourceTree = ""; }; 50AF3B111CC6FD890042F81C /* Listener.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Listener.swift; sourceTree = ""; }; 50AF3B121CC6FD890042F81C /* ListenerStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ListenerStore.swift; sourceTree = ""; }; @@ -140,7 +135,6 @@ 50AF3B0E1CC6FD890042F81C /* Sources */ = { isa = PBXGroup; children = ( - 50AF3B0F1CC6FD890042F81C /* Compatible.swift */, 50AF3B101CC6FD890042F81C /* EventSource.swift */, 50AF3B111CC6FD890042F81C /* Listener.swift */, 50AF3B121CC6FD890042F81C /* ListenerStore.swift */, @@ -284,16 +278,18 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0800; TargetAttributes = { 500E8F711CC7753F0030818B = { CreatedOnToolsVersion = 7.3; }; 50AF3AF21CC6FC3C0042F81C = { CreatedOnToolsVersion = 7.3; + LastSwiftMigration = 0800; }; 50AF3AFC1CC6FC3C0042F81C = { CreatedOnToolsVersion = 7.3; + LastSwiftMigration = 0800; }; 50E10B781CC79303002C37E3 = { CreatedOnToolsVersion = 7.3; @@ -367,7 +363,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 50E0DB761CC7CB8E00441694 /* Compatible.swift in Sources */, 50E0DB7F1CC7CB9A00441694 /* ListenerStore.swift in Sources */, 50E0DB7C1CC7CB9600441694 /* Listener.swift in Sources */, 50E0DB791CC7CB9200441694 /* EventSource.swift in Sources */, @@ -378,7 +373,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 50AF3B131CC6FD890042F81C /* Compatible.swift in Sources */, 50AF3B161CC6FD890042F81C /* ListenerStore.swift in Sources */, 50AF3B151CC6FD890042F81C /* Listener.swift in Sources */, 50AF3B141CC6FD890042F81C /* EventSource.swift in Sources */, @@ -397,7 +391,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 50E0DB771CC7CB8E00441694 /* Compatible.swift in Sources */, 50E0DB801CC7CB9B00441694 /* ListenerStore.swift in Sources */, 50E0DB7D1CC7CB9700441694 /* Listener.swift in Sources */, 50E0DB7A1CC7CB9300441694 /* EventSource.swift in Sources */, @@ -408,7 +401,6 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 50E0DB781CC7CB8F00441694 /* Compatible.swift in Sources */, 50E0DB811CC7CB9B00441694 /* ListenerStore.swift in Sources */, 50E0DB7E1CC7CB9700441694 /* Listener.swift in Sources */, 50E0DB7B1CC7CB9300441694 /* EventSource.swift in Sources */, @@ -429,7 +421,7 @@ 500E8F771CC7753F0030818B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -449,7 +441,7 @@ 500E8F781CC7753F0030818B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - CODE_SIGN_IDENTITY = "-"; + CODE_SIGN_IDENTITY = ""; COMBINE_HIDPI_IMAGES = YES; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; @@ -480,8 +472,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -530,8 +524,10 @@ CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -552,6 +548,7 @@ MACOSX_DEPLOYMENT_TARGET = 10.9; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -562,6 +559,7 @@ 50AF3B081CC6FC3C0042F81C /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -572,12 +570,14 @@ PRODUCT_BUNDLE_IDENTIFIER = com.hironytic.Eventitic; PRODUCT_NAME = Eventitic; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Debug; }; 50AF3B091CC6FC3C0042F81C /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -588,6 +588,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.hironytic.Eventitic; PRODUCT_NAME = Eventitic; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -598,6 +599,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.hironytic.EventiticTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -608,6 +610,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.hironytic.EventiticTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -615,6 +618,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -635,6 +639,7 @@ isa = XCBuildConfiguration; buildSettings = { APPLICATION_EXTENSION_API_ONLY = YES; + "CODE_SIGN_IDENTITY[sdk=watchos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -654,6 +659,7 @@ 50E10B8D1CC794AC002C37E3 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; @@ -673,6 +679,7 @@ 50E10B8E1CC794AC002C37E3 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=appletvos*]" = ""; DEFINES_MODULE = YES; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; diff --git a/Eventitic/Eventitic.xcodeproj/xcshareddata/xcschemes/Eventitic_OSX.xcscheme b/Eventitic/Eventitic.xcodeproj/xcshareddata/xcschemes/Eventitic_OSX.xcscheme index fd6515f..3a4568a 100644 --- a/Eventitic/Eventitic.xcodeproj/xcshareddata/xcschemes/Eventitic_OSX.xcscheme +++ b/Eventitic/Eventitic.xcodeproj/xcshareddata/xcschemes/Eventitic_OSX.xcscheme @@ -1,6 +1,6 @@ () - source.listen { value in + let listener = source.listen { value in values.append(value) } @@ -53,13 +53,15 @@ class EventiticTests: XCTestCase { XCTAssertEqual(values.count, 1) XCTAssertEqual(values[0], 10) + + listener.unlisten() } func testShouldListenTwoFiredEvents() { var values: [Int] = [] let source = EventSource() - source.listen { value in + let listener = source.listen { value in values.append(value) } @@ -69,6 +71,8 @@ class EventiticTests: XCTestCase { XCTAssertEqual(values.count, 2) XCTAssertEqual(values[0], 10) XCTAssertEqual(values[1], 20) + + listener.unlisten() } func testShouldDispatchToTwoListeners() { @@ -77,11 +81,11 @@ class EventiticTests: XCTestCase { let source = EventSource() - source.listen { value in + let listener1 = source.listen { value in values1.append("#1: \(value)") } - source.listen { value in + let listener2 = source.listen { value in values2.append("#2: \(value)") } @@ -91,6 +95,9 @@ class EventiticTests: XCTestCase { XCTAssertEqual(values2.count, 1) XCTAssertEqual(values1[0], "#1: foo") XCTAssertEqual(values2[0], "#2: foo") + + listener1.unlisten() + listener2.unlisten() } // MARK: Unlistening to a Event @@ -105,7 +112,7 @@ class EventiticTests: XCTestCase { values1.append("#1: \(value)") } - source.listen { value in + let listener2 = source.listen { value in values2.append("#2: \(value)") } @@ -120,6 +127,8 @@ class EventiticTests: XCTestCase { XCTAssertEqual(values1[0], "#1: foo") XCTAssertEqual(values2[0], "#2: foo") XCTAssertEqual(values2[1], "#2: bar") + + listener2.unlisten() } func testShouldUnlistenEvenInHandler() { @@ -134,7 +143,7 @@ class EventiticTests: XCTestCase { listener1?.unlisten() } - source.listen { value in + let listener2 = source.listen { value in values2.append("#2: \(value)") } @@ -146,6 +155,8 @@ class EventiticTests: XCTestCase { XCTAssertEqual(values1[0], "#1: foo") XCTAssertEqual(values2[0], "#2: foo") XCTAssertEqual(values2[1], "#2: bar") + + listener2.unlisten() } // MARK: Listener Store diff --git a/Sources/Compatible.swift b/Sources/Compatible.swift deleted file mode 100644 index 910aaf0..0000000 --- a/Sources/Compatible.swift +++ /dev/null @@ -1,44 +0,0 @@ -// -// Compatible.swift -// Eventitic -// -// Copyright (c) 2016 Hironori Ichimiya -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// - -import Foundation - -#if swift(>=3.0) -#else - - extension CollectionType where Generator.Element : Equatable { - @warn_unused_result - func index(of element: Self.Generator.Element) -> Self.Index? { - return self.indexOf(element) - } - } - - extension Array { - mutating func remove(at index: Int) -> Element { - return self.removeAtIndex(index) - } - } - -#endif diff --git a/Sources/EventSource.swift b/Sources/EventSource.swift index 1cb7e68..543b5e8 100644 --- a/Sources/EventSource.swift +++ b/Sources/EventSource.swift @@ -25,16 +25,16 @@ import Foundation -private class UnlistenPool { - private var listeners: [Listener] = [] +fileprivate class UnlistenPool { + fileprivate var listeners: [Listener] = [] } /// /// This class represents a source of events. /// -public class EventSource { - private var listeners: [Listener] - private var unlistenPools: [UnlistenPool] +open class EventSource { + fileprivate var listeners: [Listener] + fileprivate var unlistenPools: [UnlistenPool] /// /// Initializes an event source. @@ -50,7 +50,7 @@ public class EventSource { /// - Parameter handler: A closure which handles events. /// - Returns: A listener object. /// - public func listen(_ handler: T -> Void) -> Listener { + open func listen(_ handler: @escaping (T) -> Void) -> Listener { let listener = Listener(eventSource: self, handler: handler) listeners.append(listener) return listener @@ -71,7 +71,7 @@ public class EventSource { /// /// - Parameter value: An event value. /// - public func fire(_ value: T) { + open func fire(_ value: T) { unlistenPools.append(UnlistenPool()) listeners.forEach { listener in diff --git a/Sources/Listener.swift b/Sources/Listener.swift index 39ebf2a..b636c7c 100644 --- a/Sources/Listener.swift +++ b/Sources/Listener.swift @@ -38,13 +38,13 @@ public protocol Unlistenable { /// /// This class represents a listener of specific event source. /// -public class Listener: Unlistenable, Equatable { - public typealias Handler = T -> Void +open class Listener: Unlistenable, Equatable { + public typealias Handler = (T) -> Void - private let eventSource: EventSource - private let handler: Handler + fileprivate let eventSource: EventSource + fileprivate let handler: Handler - init(eventSource: EventSource, handler: Handler) { + init(eventSource: EventSource, handler: @escaping Handler) { self.eventSource = eventSource self.handler = handler } @@ -56,7 +56,7 @@ public class Listener: Unlistenable, Equatable { /// /// Stops listening. /// - public func unlisten() { + open func unlisten() { eventSource.unlisten(self) } @@ -67,7 +67,8 @@ public class Listener: Unlistenable, Equatable { /// - Parameter listenerStore: A listener store to which this object is added. /// - SeeAlso: `ListenerStore.add(_:)` /// - public func addToStore(listenerStore: ListenerStore) { + @available(*, deprecated: 1.1.0, renamed: "add(to:)") + open func addToStore(_ listenerStore: ListenerStore) { listenerStore.add(self) } @@ -78,7 +79,7 @@ public class Listener: Unlistenable, Equatable { /// - Parameter listenerStore: A listener store to which this object is added. /// - SeeAlso: `ListenerStore.add(_:)` /// - public func add(to listenerStore: ListenerStore) { + open func add(to listenerStore: ListenerStore) { listenerStore.add(self) } } diff --git a/Sources/ListenerStore.swift b/Sources/ListenerStore.swift index 3bf4d49..9df3b64 100644 --- a/Sources/ListenerStore.swift +++ b/Sources/ListenerStore.swift @@ -28,8 +28,8 @@ import Foundation /// /// This is a utility class which holds listeners and makes it possible to unlisten them all. /// -public class ListenerStore { - private var items: [Unlistenable] +open class ListenerStore { + fileprivate var items: [Unlistenable] /// Initializes an object. public init() { @@ -45,14 +45,14 @@ public class ListenerStore { /// /// - Parameter listener: A listener which will be added to this store. /// - public func add(_ listener: Unlistenable) { + open func add(_ listener: Unlistenable) { items.append(listener) } /// /// Makes all listeners in this store unlisten. /// - public func unlistenAll() { + open func unlistenAll() { items.forEach { $0.unlisten() } items.removeAll() } From 6ffb4bbca906fb0c08dfce0bd108a2b592c2e559 Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Thu, 8 Sep 2016 20:39:19 +0900 Subject: [PATCH 07/16] Remove `Listener.add(to:)` after all --- Eventitic/EventiticTests/EventiticTests.swift | 2 +- README.md | 6 +++--- Sources/Listener.swift | 12 ------------ 3 files changed, 4 insertions(+), 16 deletions(-) diff --git a/Eventitic/EventiticTests/EventiticTests.swift b/Eventitic/EventiticTests/EventiticTests.swift index 142ea63..7ede829 100644 --- a/Eventitic/EventiticTests/EventiticTests.swift +++ b/Eventitic/EventiticTests/EventiticTests.swift @@ -175,7 +175,7 @@ class EventiticTests: XCTestCase { source.listen { value in values2.append("#2: \(value)") - }.add(to: listenerStore) + }.addToStore(listenerStore) source.fire("foo") diff --git a/README.md b/README.md index e69430f..35243ef 100644 --- a/README.md +++ b/README.md @@ -38,15 +38,15 @@ let source2 = EventSource() // listen source1.listen { message in print("listener 1: \(message)") -}.add(to: store) +}.addToStore(store) source1.listen { message in print("listener 2: \(message)") -}.add(to: store) +}.addToStore(store) source2.listen { value in print("listener 3: \(value)") -}.add(to: store) +}.addToStore(store) // dispatch source1.fire("foo") diff --git a/Sources/Listener.swift b/Sources/Listener.swift index b636c7c..245c2f5 100644 --- a/Sources/Listener.swift +++ b/Sources/Listener.swift @@ -67,21 +67,9 @@ open class Listener: Unlistenable, Equatable { /// - Parameter listenerStore: A listener store to which this object is added. /// - SeeAlso: `ListenerStore.add(_:)` /// - @available(*, deprecated: 1.1.0, renamed: "add(to:)") open func addToStore(_ listenerStore: ListenerStore) { listenerStore.add(self) } - - /// - /// Adds this object to specified listener store. - /// Calling this method is equivalent to calling `ListenerStore.add(_:)` with this object as a parameter. - /// - /// - Parameter listenerStore: A listener store to which this object is added. - /// - SeeAlso: `ListenerStore.add(_:)` - /// - open func add(to listenerStore: ListenerStore) { - listenerStore.add(self) - } } /// From f32b396068d688a9721f9745250c85200c67f6b7 Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Thu, 8 Sep 2016 20:54:03 +0900 Subject: [PATCH 08/16] Bump version to 2.0.0 --- Eventitic.podspec | 2 +- Eventitic/Eventitic/Info.plist | 2 +- README.md | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Eventitic.podspec b/Eventitic.podspec index 4004520..9862af9 100644 --- a/Eventitic.podspec +++ b/Eventitic.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = "Eventitic" - s.version = "1.0.1" + s.version = "2.0.0" s.summary = "Dispatching and listening events" s.description = <<-DESC diff --git a/Eventitic/Eventitic/Info.plist b/Eventitic/Eventitic/Info.plist index 7a84553..7e7479f 100644 --- a/Eventitic/Eventitic/Info.plist +++ b/Eventitic/Eventitic/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0.1 + 2.0.0 CFBundleSignature ???? CFBundleVersion diff --git a/README.md b/README.md index 35243ef..6c2cccf 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ store.unlistenAll() - OS X 10.9+ - watchOS 2.0+ - tvOS 9.0+ -- Swift 2.2+ +- Swift 3.0+ ## Installation @@ -73,7 +73,7 @@ To install it, simply add the following lines to your Podfile: ```ruby use_frameworks! -pod "Eventitic", '~> 1.0' +pod "Eventitic", '~> 2.0' ``` ### Carthage @@ -82,7 +82,7 @@ Eventitic is available through [Carthage](https://github.com/Carthage/Carthage). To install it, simply add the following line to your Cartfile: ``` -github "hironytic/Eventitic" ~> 1.0 +github "hironytic/Eventitic" ~> 2.0 ``` ### Swift Package Manager @@ -96,7 +96,7 @@ import PackageDescription let package = Package( name: "Hello", dependencies: [ - .Package(url: "https://github.com/hironytic/Eventitic.git", majorVersion: 1), + .Package(url: "https://github.com/hironytic/Eventitic.git", majorVersion: 2), ] ) ``` From fa88ee37c5d7460db26868052d471d9f3512661d Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Thu, 8 Sep 2016 20:54:27 +0900 Subject: [PATCH 09/16] Update travis settings to use Xcode 8 image --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index c0b34ec..a5f45c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,12 +3,12 @@ # * https://github.com/supermarin/xcpretty#usage language: objective-c -osx_image: xcode7.3 +osx_image: xcode8 # cache: cocoapods # podfile: Example/Podfile # before_install: # - gem install cocoapods # Since Travis is not always on latest version # - pod install --project-directory=Example script: -- set -o pipefail && xcodebuild test -project Eventitic/Eventitic.xcodeproj -scheme Eventitic_iOS -destination 'platform=iOS Simulator,name=iPhone 5s' ONLY_ACTIVE_ARCH=NO | xcpretty +- set -o pipefail && xcodebuild test -project Eventitic/Eventitic.xcodeproj -scheme Eventitic_iOS -destination 'platform=iOS Simulator,name=iPhone 7' ONLY_ACTIVE_ARCH=NO | xcpretty - pod lib lint --allow-warnings From 9c867f52ca60e9def18167b37e20c116da6b4e92 Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Thu, 8 Sep 2016 21:22:50 +0900 Subject: [PATCH 10/16] Updated to Swift 3 in macOS, watchOS and tvOS targets --- Eventitic/Eventitic.xcodeproj/project.pbxproj | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Eventitic/Eventitic.xcodeproj/project.pbxproj b/Eventitic/Eventitic.xcodeproj/project.pbxproj index 6988593..1752bc4 100644 --- a/Eventitic/Eventitic.xcodeproj/project.pbxproj +++ b/Eventitic/Eventitic.xcodeproj/project.pbxproj @@ -282,6 +282,7 @@ TargetAttributes = { 500E8F711CC7753F0030818B = { CreatedOnToolsVersion = 7.3; + LastSwiftMigration = 0800; }; 50AF3AF21CC6FC3C0042F81C = { CreatedOnToolsVersion = 7.3; @@ -293,9 +294,11 @@ }; 50E10B781CC79303002C37E3 = { CreatedOnToolsVersion = 7.3; + LastSwiftMigration = 0800; }; 50E10B861CC794AC002C37E3 = { CreatedOnToolsVersion = 7.3; + LastSwiftMigration = 0800; }; }; }; @@ -435,6 +438,7 @@ PRODUCT_NAME = Eventitic; SDKROOT = macosx; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -455,6 +459,7 @@ PRODUCT_NAME = Eventitic; SDKROOT = macosx; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -630,6 +635,7 @@ PRODUCT_NAME = Eventitic; SDKROOT = watchos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 2.2; }; @@ -651,6 +657,7 @@ PRODUCT_NAME = Eventitic; SDKROOT = watchos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 4; WATCHOS_DEPLOYMENT_TARGET = 2.2; }; @@ -671,6 +678,7 @@ PRODUCT_NAME = Eventitic; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; @@ -691,6 +699,7 @@ PRODUCT_NAME = Eventitic; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; }; From 3293bb93ffab29bade16c70ce95ecb482d1a068f Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Thu, 29 Sep 2016 19:36:50 +0900 Subject: [PATCH 11/16] Add .swift-version --- .swift-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .swift-version diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..9f55b2c --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +3.0 From 8888646bb2ca11a5ea39869b71d21bb8de3036af Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Thu, 29 Sep 2016 19:55:09 +0900 Subject: [PATCH 12/16] Update travis setting for CocoaPods 1.1.0.rc.2 --- .travis.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a5f45c6..371c57e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,10 @@ language: objective-c osx_image: xcode8 -# cache: cocoapods +cache: cocoapods # podfile: Example/Podfile -# before_install: +before_install: +gem install cocoapods --pre # for 1.1.0.rc.2 # - gem install cocoapods # Since Travis is not always on latest version # - pod install --project-directory=Example script: From 5d5a8ba1bb6a44a0b608f65ff8ccc802e3c05adb Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Thu, 29 Sep 2016 19:56:41 +0900 Subject: [PATCH 13/16] Fix .travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 371c57e..f467644 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ osx_image: xcode8 cache: cocoapods # podfile: Example/Podfile before_install: -gem install cocoapods --pre # for 1.1.0.rc.2 +- gem install cocoapods --pre # for 1.1.0.rc.2 # - gem install cocoapods # Since Travis is not always on latest version # - pod install --project-directory=Example script: From bdc3465281c92692d7cc6dc3a8030f43cbbe6848 Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Thu, 29 Sep 2016 20:22:14 +0900 Subject: [PATCH 14/16] Fix access control level --- Sources/EventSource.swift | 14 +++++++------- Sources/Listener.swift | 10 +++++----- Sources/ListenerStore.swift | 8 ++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/Sources/EventSource.swift b/Sources/EventSource.swift index 543b5e8..2ecedac 100644 --- a/Sources/EventSource.swift +++ b/Sources/EventSource.swift @@ -25,16 +25,16 @@ import Foundation -fileprivate class UnlistenPool { - fileprivate var listeners: [Listener] = [] +private class UnlistenPool { + var listeners: [Listener] = [] } /// /// This class represents a source of events. /// -open class EventSource { - fileprivate var listeners: [Listener] - fileprivate var unlistenPools: [UnlistenPool] +public class EventSource { + private var listeners: [Listener] + private var unlistenPools: [UnlistenPool] /// /// Initializes an event source. @@ -50,7 +50,7 @@ open class EventSource { /// - Parameter handler: A closure which handles events. /// - Returns: A listener object. /// - open func listen(_ handler: @escaping (T) -> Void) -> Listener { + public func listen(_ handler: @escaping (T) -> Void) -> Listener { let listener = Listener(eventSource: self, handler: handler) listeners.append(listener) return listener @@ -71,7 +71,7 @@ open class EventSource { /// /// - Parameter value: An event value. /// - open func fire(_ value: T) { + public func fire(_ value: T) { unlistenPools.append(UnlistenPool()) listeners.forEach { listener in diff --git a/Sources/Listener.swift b/Sources/Listener.swift index 245c2f5..ac42dd5 100644 --- a/Sources/Listener.swift +++ b/Sources/Listener.swift @@ -38,11 +38,11 @@ public protocol Unlistenable { /// /// This class represents a listener of specific event source. /// -open class Listener: Unlistenable, Equatable { +public class Listener: Unlistenable, Equatable { public typealias Handler = (T) -> Void - fileprivate let eventSource: EventSource - fileprivate let handler: Handler + private let eventSource: EventSource + private let handler: Handler init(eventSource: EventSource, handler: @escaping Handler) { self.eventSource = eventSource @@ -56,7 +56,7 @@ open class Listener: Unlistenable, Equatable { /// /// Stops listening. /// - open func unlisten() { + public func unlisten() { eventSource.unlisten(self) } @@ -67,7 +67,7 @@ open class Listener: Unlistenable, Equatable { /// - Parameter listenerStore: A listener store to which this object is added. /// - SeeAlso: `ListenerStore.add(_:)` /// - open func addToStore(_ listenerStore: ListenerStore) { + public func addToStore(_ listenerStore: ListenerStore) { listenerStore.add(self) } } diff --git a/Sources/ListenerStore.swift b/Sources/ListenerStore.swift index 9df3b64..3bf4d49 100644 --- a/Sources/ListenerStore.swift +++ b/Sources/ListenerStore.swift @@ -28,8 +28,8 @@ import Foundation /// /// This is a utility class which holds listeners and makes it possible to unlisten them all. /// -open class ListenerStore { - fileprivate var items: [Unlistenable] +public class ListenerStore { + private var items: [Unlistenable] /// Initializes an object. public init() { @@ -45,14 +45,14 @@ open class ListenerStore { /// /// - Parameter listener: A listener which will be added to this store. /// - open func add(_ listener: Unlistenable) { + public func add(_ listener: Unlistenable) { items.append(listener) } /// /// Makes all listeners in this store unlisten. /// - open func unlistenAll() { + public func unlistenAll() { items.forEach { $0.unlisten() } items.removeAll() } From b21d8988447ba502c96d37f662298cb2918147d2 Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Tue, 25 Oct 2016 19:14:23 +0900 Subject: [PATCH 15/16] Update travis setting --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index f467644..32d934a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,7 @@ osx_image: xcode8 cache: cocoapods # podfile: Example/Podfile before_install: -- gem install cocoapods --pre # for 1.1.0.rc.2 -# - gem install cocoapods # Since Travis is not always on latest version +- gem install cocoapods # Since Travis is not always on latest version # - pod install --project-directory=Example script: - set -o pipefail && xcodebuild test -project Eventitic/Eventitic.xcodeproj -scheme Eventitic_iOS -destination 'platform=iOS Simulator,name=iPhone 7' ONLY_ACTIVE_ARCH=NO | xcpretty From 7ef6d7bb979b0175461403c97862bd6bb8ff9358 Mon Sep 17 00:00:00 2001 From: Hironori Ichimiya Date: Tue, 25 Oct 2016 19:24:01 +0900 Subject: [PATCH 16/16] Update travis setting again --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 32d934a..417e452 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ language: objective-c osx_image: xcode8 -cache: cocoapods +# cache: cocoapods # podfile: Example/Podfile before_install: - gem install cocoapods # Since Travis is not always on latest version