Skip to content

Commit

Permalink
Restore Swift 3.1 compatibility
Browse files Browse the repository at this point in the history
We don't actually need Swift 4 for the new `KeyPath` APIs.
  • Loading branch information
Kevin Ballard committed Sep 13, 2017
1 parent 5d0600e commit a1eacc8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 16 deletions.
8 changes: 4 additions & 4 deletions PMKVObserver.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx watchsimulator watchos appletvsimulator appletvos";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -391,7 +391,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx watchsimulator watchos appletvsimulator appletvos";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand All @@ -407,7 +407,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "macosx iphonesimulator iphoneos appletvsimulator appletvos";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -422,7 +422,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.postmates.PMKVObserverTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTED_PLATFORMS = "macosx iphonesimulator iphoneos appletvsimulator appletvos";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
2 changes: 2 additions & 0 deletions PMKVObserver/KVObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Foundation
public typealias KVObserver = PMKVObserver

extension KVObserver {
#if swift(>=3.2)
/// Establishes a KVO relationship to `object`. The KVO will be active until `object` deallocates or
/// until the `cancel()` method is invoked.
public convenience init<Object: AnyObject, Value>(object: Object, keyPath: KeyPath<Object,Value>, options: NSKeyValueObservingOptions = [], block: @escaping (_ object: Object, _ change: Change<Value>, _ kvo: KVObserver) -> Void) {
Expand All @@ -40,6 +41,7 @@ extension KVObserver {
block(unsafeDowncast(observer as AnyObject, to: T.self), unsafeDowncast(object as AnyObject, to: Object.self), Change(rawDict: change), kvo)
})
}
#endif

/// Establishes a KVO relationship to `object`. The KVO will be active until `object` deallocates or
/// until the `cancel()` method is invoked.
Expand Down
2 changes: 2 additions & 0 deletions PMKVObserverTests/KVObserverTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class KVObserverTests: XCTestCase {
fired = false
}

#if swift(>=3.2)
func testSwift4KVO() {
var fired = false
var token: KVObserver!
Expand Down Expand Up @@ -120,6 +121,7 @@ class KVObserverTests: XCTestCase {
token.cancel()
fired = false
}
#endif

func testInitialCancel() {
var fired = false
Expand Down
18 changes: 6 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ Installing as a framework requires a minimum of iOS 8, OS X 10.9, watchOS 2.0, o
If you install by copying the source into your project, it should work on iOS 7 or later (iOS 6 if you remove KVObserver.swift), and OS X 10.7 or later. Please note that it has not been tested on these versions.
PMKVObserver will compile with Xcode 8.3, but the new `KeyPath` APIs require Xcode 9 or later.
## Installation
After installing with any mechanism, you can use this by adding `import PMKVObserver` (Swift) or `@import PMKVObserver;` (Objective-C) to your code.
Expand All @@ -102,12 +104,6 @@ To install using [Carthage][], add the following to your Cartfile:
github "postmates/PMKVObserver" ~> 3.0
```
This version supports Swift 4.0. For Swift 3, use the following instead:
```
github "postmates/PMKVObserver" ~> 2.0
```
### CocoaPods
To install using [CocoaPods][], add the following to your Podfile:
Expand All @@ -116,12 +112,6 @@ To install using [CocoaPods][], add the following to your Podfile:
pod 'PMKVObserver', '~> 3.0'
```
This release supports Swift 4. If you want Swift 3 support, you can use
```
pod 'PMKVObserver', '~> 2.0'
```
[CocoaPods]: https://cocoapods.org
### Manual Installation
Expand All @@ -142,6 +132,10 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
## Version History
#### Development
* Set Swift version back to Swift 3.2. The new `KeyPath` stuff is usable from 3.2 so there's no reason to require 4. PMVKObserver will still compile with Swift 3.1, but the `KeyPath` APIs won't be available unless compiling with Swift 3.2.
#### v3.0.0 (2017-09-12)
* Convert to Swift 4.
Expand Down

0 comments on commit a1eacc8

Please sign in to comment.