Skip to content

Commit

Permalink
Merge pull request #2 from sebskuse/feature/swift_5
Browse files Browse the repository at this point in the history
Swift 5 support
  • Loading branch information
dhardiman authored Apr 25, 2019
2 parents 24e3e28 + 6a6beba commit 435b7bf
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 85 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5.0
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "Quick/Nimble" "v7.3.1"
github "Quick/Nimble" "v8.0.1"
28 changes: 14 additions & 14 deletions Spot.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
077B35401F7BA13D0000282F /* LocationHandlerPermissionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FFC2D451E3A24F000080DD9 /* LocationHandlerPermissionTests.swift */; };
077B35411F7BA9DD0000282F /* LocationHandlerRequestTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FA74A291E3752F90014BD82 /* LocationHandlerRequestTests.swift */; };
077B35421F7BAF2B0000282F /* LocationServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F44F4E71E379C3E000BBC4E /* LocationServiceTests.swift */; };
4F3399B51E3A0AD5002634E5 /* LocationResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F44F4DC1E376D31000BBC4E /* LocationResult.swift */; };
4F3399B91E3A0C05002634E5 /* LocationAccess.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F44F4DE1E37770C000BBC4E /* LocationAccess.swift */; };
4F44F4D21E376C2F000BBC4E /* MockLocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F44F4D11E376C2F000BBC4E /* MockLocationManager.swift */; };
4F44F4E11E37775D000BBC4E /* LocationAccessTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4F44F4E01E37775D000BBC4E /* LocationAccessTests.swift */; };
Expand Down Expand Up @@ -41,7 +40,6 @@
077B353E1F7B955B0000282F /* LocationHandlerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationHandlerTests.swift; sourceTree = "<group>"; };
4F44F4D11E376C2F000BBC4E /* MockLocationManager.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MockLocationManager.swift; sourceTree = "<group>"; };
4F44F4DA1E376CB8000BBC4E /* CLLocationCoordinate2D+Equatable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "CLLocationCoordinate2D+Equatable.swift"; sourceTree = "<group>"; };
4F44F4DC1E376D31000BBC4E /* LocationResult.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationResult.swift; sourceTree = "<group>"; };
4F44F4DE1E37770C000BBC4E /* LocationAccess.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationAccess.swift; sourceTree = "<group>"; };
4F44F4E01E37775D000BBC4E /* LocationAccessTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LocationAccessTests.swift; sourceTree = "<group>"; };
4F44F4E21E377DF6000BBC4E /* LocationManagerType+Mocks.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "LocationManagerType+Mocks.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -122,7 +120,6 @@
4F9DE3D81E365F49009013B4 /* Info.plist */,
4F9DE3D71E365F49009013B4 /* Spot.h */,
4F44F4DE1E37770C000BBC4E /* LocationAccess.swift */,
4F44F4DC1E376D31000BBC4E /* LocationResult.swift */,
4F44F4E51E3797C5000BBC4E /* LocationService.swift */,
077B353C1F7B90FC0000282F /* LocationHandler.swift */,
);
Expand Down Expand Up @@ -212,27 +209,28 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0930;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = "David Hardiman";
TargetAttributes = {
4F9DE3D31E365F49009013B4 = {
CreatedOnToolsVersion = 8.2.1;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
4F9DE3DC1E365F49009013B4 = {
CreatedOnToolsVersion = 8.2.1;
LastSwiftMigration = 1000;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
};
};
buildConfigurationList = 4F9DE3CE1E365F49009013B4 /* Build configuration list for PBXProject "Spot" */;
compatibilityVersion = "Xcode 9.3";
developmentRegion = English;
developmentRegion = en;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
mainGroup = 4F9DE3CA1E365F49009013B4;
productRefGroup = 4F9DE3D51E365F49009013B4 /* Products */;
Expand Down Expand Up @@ -304,7 +302,6 @@
files = (
077B353D1F7B90FC0000282F /* LocationHandler.swift in Sources */,
4F3399B91E3A0C05002634E5 /* LocationAccess.swift in Sources */,
4F3399B51E3A0AD5002634E5 /* LocationResult.swift in Sources */,
4F44F4E61E3797C5000BBC4E /* LocationService.swift in Sources */,
4F44F4E41E378D2D000BBC4E /* CLLocationCoordinate2D+Equatable.swift in Sources */,
);
Expand Down Expand Up @@ -341,6 +338,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
Expand Down Expand Up @@ -421,7 +419,7 @@
SKIP_INSTALL = YES;
SWIFT_COMPILATION_MODE = singlefile;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Calabash;
};
Expand All @@ -439,14 +437,15 @@
);
PRODUCT_BUNDLE_IDENTIFIER = me.davidhardiman.SpotTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Calabash;
};
4F9DE3E61E365F49009013B4 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
Expand Down Expand Up @@ -509,6 +508,7 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
Expand Down Expand Up @@ -583,7 +583,7 @@
SKIP_INSTALL = YES;
SWIFT_COMPILATION_MODE = singlefile;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -607,7 +607,7 @@
PRODUCT_BUNDLE_IDENTIFIER = me.davidhardiman.SPOT;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -625,7 +625,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = me.davidhardiman.SpotTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -643,7 +643,7 @@
);
PRODUCT_BUNDLE_IDENTIFIER = me.davidhardiman.SpotTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion Spot.xcodeproj/xcshareddata/xcschemes/Spot.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1000"
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
4 changes: 3 additions & 1 deletion Spot/LocationAccess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import CoreLocation

public protocol AuthorizationManaging: class {
public protocol AuthorizationManaging: AnyObject {
static func locationServicesEnabled() -> Bool
static func authorizationStatus() -> CLAuthorizationStatus
}
Expand Down Expand Up @@ -59,6 +59,8 @@ open class LocationAccess {
return false
case .authorizedAlways, .authorizedWhenInUse:
return true
@unknown default:
return false
}
}
}
10 changes: 6 additions & 4 deletions Spot/LocationHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import CoreLocation
import Foundation

public typealias LocationCompletion = ((LocationResult<CLLocationCoordinate2D, LocationRequestError>) -> Void)
public typealias LocationCompletion = ((Result<CLLocationCoordinate2D, LocationRequestError>) -> Void)

public protocol LocationHandling: class {
public protocol LocationHandling: AnyObject {
func requestLocation(_ completion: @escaping LocationCompletion)
func cancelCurrentRequest()
var didChangeAuthorizationStatus: ((LocationResult<Void, LocationPermissionError>) -> Void)? { get set }
var didChangeAuthorizationStatus: ((Result<Void, LocationPermissionError>) -> Void)? { get set }
}

// MARK: - CLLocationManagerDelegate
Expand All @@ -26,7 +26,7 @@ class LocationHandler: NSObject, LocationHandling, CLLocationManagerDelegate {
let locationAccess: LocationAccess

/// Closure called when authorization status changes
var didChangeAuthorizationStatus: ((LocationResult<Void, LocationPermissionError>) -> Void)?
var didChangeAuthorizationStatus: ((Result<Void, LocationPermissionError>) -> Void)?

init(locationManager: LocationManaging, locationAccess: LocationAccess = LocationAccess()) {
self.locationManager = locationManager
Expand Down Expand Up @@ -104,6 +104,8 @@ class LocationHandler: NSObject, LocationHandling, CLLocationManagerDelegate {
case .notDetermined:
// Not determined is the initial state and is not used for observing changes to the authorization status
break
@unknown default:
break
}
}
}
40 changes: 0 additions & 40 deletions Spot/LocationResult.swift

This file was deleted.

8 changes: 4 additions & 4 deletions Spot/LocationService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ public protocol LocationReporting {
/// Method to request a users location
///
/// - Parameter completion: Completion including the result of the request
func requestLocation(completion: @escaping (LocationResult<CLLocationCoordinate2D, LocationRequestError>) -> Void)
func requestLocation(completion: @escaping (Result<CLLocationCoordinate2D, LocationRequestError>) -> Void)

/// Cancel all requests for location
func cancelRequestingLocation()

/// Register to observe authorisation changes
///
/// - Parameter changesHandler: Closure to call when changes happen
func observeAuthorizationChanges(changesHandler: @escaping (LocationResult<Void, LocationPermissionError>) -> Void)
func observeAuthorizationChanges(changesHandler: @escaping (Result<Void, LocationPermissionError>) -> Void)
}

/// The operation context to use get a user location
Expand All @@ -74,15 +74,15 @@ public class LocationService: LocationReporting {
self.locationHandler = locationHandler
}

public func requestLocation(completion: @escaping (LocationResult<CLLocationCoordinate2D, LocationRequestError>) -> Void) {
public func requestLocation(completion: @escaping (Result<CLLocationCoordinate2D, LocationRequestError>) -> Void) {
locationHandler.requestLocation(completion)
}

public func cancelRequestingLocation() {
locationHandler.cancelCurrentRequest()
}

public func observeAuthorizationChanges(changesHandler: @escaping (LocationResult<Void, LocationPermissionError>) -> Void) {
public func observeAuthorizationChanges(changesHandler: @escaping (Result<Void, LocationPermissionError>) -> Void) {
locationHandler.didChangeAuthorizationStatus = changesHandler
}
}
4 changes: 2 additions & 2 deletions SpotTests/LocationHandlerAuthorisationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension LocationHandlerTests {
func givenSuccessExpectation() {
let closureExpectation = expectation(description: #function)
handler.didChangeAuthorizationStatus = { result in
expect(result.successResult()).toNot(beNil())
expect(try? result.get()).toNot(beNil())
closureExpectation.fulfill()
}
}
Expand All @@ -34,7 +34,7 @@ extension LocationHandlerTests {
func givenExpectationForFailure(with error: LocationPermissionError) {
let closureExpectation = expectation(description: #function)
handler.didChangeAuthorizationStatus = { result in
expect(result.error()).to(equal(error))
expect(result.error).to(equal(error))
closureExpectation.fulfill()
}
}
Expand Down
12 changes: 6 additions & 6 deletions SpotTests/LocationHandlerPermissionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ extension LocationHandlerTests {

func testLocationRequestReturnsDisabledErrorWhenLocationServicesAreDisabled() {
MockLocationManager.isLocationServicesEnabled = false
var receivedResult: LocationResult<CLLocationCoordinate2D, LocationRequestError>?
var receivedResult: Result<CLLocationCoordinate2D, LocationRequestError>?
handler.requestLocation { result in
receivedResult = result
}
expect(receivedResult!.error()).to(equal(LocationRequestError.locationDisabled))
expect(receivedResult!.error).to(equal(LocationRequestError.locationDisabled))
}

func testLocationRequestIsInitiatedWhenAuthorizationStatusIsAuthorizedAlways() {
Expand All @@ -69,22 +69,22 @@ extension LocationHandlerTests {

func testLocationRequestReportsErrorWhenAuthorizationStatusIsDenied() {
givenLocationPermissionHasNotBeenRequested()
var receivedResult: LocationResult<CLLocationCoordinate2D, LocationRequestError>?
var receivedResult: Result<CLLocationCoordinate2D, LocationRequestError>?
handler.requestLocation { result in
receivedResult = result
}
whenLocationPermissionIsReceived(withStatus: .denied)
expect(receivedResult!.error()).to(equal(LocationRequestError.locationDenied))
expect(receivedResult!.error).to(equal(LocationRequestError.locationDenied))
}

func testLocationRequestReportsErrorWhenAuthorizationStatusIsRestricted() {
givenLocationPermissionHasNotBeenRequested()
var receivedResult: LocationResult<CLLocationCoordinate2D, LocationRequestError>?
var receivedResult: Result<CLLocationCoordinate2D, LocationRequestError>?
handler.requestLocation { result in
receivedResult = result
}
whenLocationPermissionIsReceived(withStatus: .restricted)
expect(receivedResult!.error()).to(equal(LocationRequestError.locationDenied))
expect(receivedResult!.error).to(equal(LocationRequestError.locationDenied))
}
}

Expand Down
Loading

0 comments on commit 435b7bf

Please sign in to comment.