diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 03dffb415..5b29107f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: env: DEVELOPER_DIR: ${{ env.CI_XCODE_13 }} - name: Build-Test - run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(iOS\) -destination platform\=iOS\ Simulator,name\=iPhone\ 12\ Pro\ Max -derivedDataPath DerivedData test | xcpretty + run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(iOS\) -destination platform\=iOS\ Simulator,name\=iPhone\ 12\ Pro\ Max -derivedDataPath DerivedData clean test | xcpretty env: DEVELOPER_DIR: ${{ env.CI_XCODE_13 }} - name: Prepare codecov @@ -49,7 +49,7 @@ jobs: security unlock-keychain -p "" temporary security set-keychain-settings -lut 7200 temporary - name: Build-Test - run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(macOS\) -destination platform\=macOS -derivedDataPath DerivedData test | xcpretty + run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(macOS\) -destination platform\=macOS -derivedDataPath DerivedData clean test | xcpretty env: DEVELOPER_DIR: ${{ env.CI_XCODE_13 }} - name: Prepare codecov @@ -74,7 +74,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Build - run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(tvOS\) -destination platform\=tvOS\ Simulator,name\=Apple\ TV -derivedDataPath DerivedData test | xcpretty + run: set -o pipefail && env NSUnbufferedIO=YES xcodebuild -workspace Parse.xcworkspace -scheme ParseSwift\ \(tvOS\) -destination platform\=tvOS\ Simulator,name\=Apple\ TV -derivedDataPath DerivedData clean test | xcpretty env: DEVELOPER_DIR: ${{ env.CI_XCODE_13 }} - name: Prepare codecov diff --git a/ParseSwift.xcodeproj/project.pbxproj b/ParseSwift.xcodeproj/project.pbxproj index f819d2a74..a5e31b8c7 100644 --- a/ParseSwift.xcodeproj/project.pbxproj +++ b/ParseSwift.xcodeproj/project.pbxproj @@ -2014,7 +2014,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "if which swiftlint >/dev/null; then\n swiftlint --fix && swiftlint --strict\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; + shellScript = "if test -d \"/opt/homebrew/bin/\"; then\n PATH=\"/opt/homebrew/bin/:${PATH}\"\nfi\n\nexport PATH\n\nif which swiftlint >/dev/null; then\n swiftlint --fix && swiftlint --strict\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n"; }; 918CED61268A23A700CFDC83 /* SwiftLint */ = { isa = PBXShellScriptBuildPhase; diff --git a/Sources/ParseSwift/Types/ParseGeoPoint.swift b/Sources/ParseSwift/Types/ParseGeoPoint.swift index a17580e6f..bfb89f076 100644 --- a/Sources/ParseSwift/Types/ParseGeoPoint.swift +++ b/Sources/ParseSwift/Types/ParseGeoPoint.swift @@ -40,7 +40,7 @@ public struct ParseGeoPoint: Codable, Hashable { Create a new `ParseGeoPoint` instance with the specified latitude and longitude. - parameter latitude: Latitude of point in degrees. - parameter longitude: Longitude of point in degrees. - - throws: `ParseError`. + - throws: An error of `ParseError` type. */ public init(latitude: Double, longitude: Double) throws { self.latitude = latitude @@ -64,19 +64,6 @@ public struct ParseGeoPoint: Codable, Hashable { } } - #if canImport(CoreLocation) - /** - Creates a new `ParseGeoPoint` instance for the given `CLLocation`, set to the location's coordinates. - - parameter location: Instance of `CLLocation`, with set latitude and longitude. - - throws: `ParseError`. - */ - public init(location: CLLocation) throws { - self.longitude = location.coordinate.longitude - self.latitude = location.coordinate.latitude - try validate() - } - #endif - /** Get distance in radians from this point to specified point. @@ -102,7 +89,6 @@ public struct ParseGeoPoint: Codable, Hashable { /** Get distance in miles from this point to specified point. - - parameter point: `ParseGeoPoint` that represents the location of other point. - returns: Distance in miles between the receiver and `point`. */ @@ -154,3 +140,49 @@ extension ParseGeoPoint: CustomStringConvertible { debugDescription } } + +#if canImport(CoreLocation) +// MARK: CLLocation +public extension ParseGeoPoint { + + /** + Creates a new `ParseGeoPoint` instance for the given `CLLocation`, set to the location's coordinates. + - parameter location: Instance of `CLLocation`, with set latitude and longitude. + - throws: An error of `ParseError` type. + */ + init(location: CLLocation) throws { + self.longitude = location.coordinate.longitude + self.latitude = location.coordinate.latitude + try validate() + } + + /** + Creates a new `ParseGeoPoint` instance for the given `CLLocationCoordinate2D`, set to the location's coordinates. + - parameter location: Instance of `CLLocationCoordinate2D`, with set latitude and longitude. + - throws: An error of `ParseError` type. + */ + init(coordinate: CLLocationCoordinate2D) throws { + self.longitude = coordinate.longitude + self.latitude = coordinate.latitude + try validate() + } + + /** + Creates a new `CLLocation` instance for the given `ParseGeoPoint`, set to the location's coordinates. + - parameter geopoint: Instance of `ParseGeoPoint`, with set latitude and longitude. + - returns: Returns a `CLLocation`. + */ + func toCLLocation() -> CLLocation { + CLLocation(latitude: latitude, longitude: longitude) + } + + /** + Creates a new `CLLocationCoordinate2D` instance for the given `ParseGeoPoint`, set to the location's coordinates. + - parameter geopoint: Instance of `ParseGeoPoint`, with set latitude and longitude. + - returns: Returns a `CLLocationCoordinate2D`. + */ + func toCLLocationCoordinate2D() -> CLLocationCoordinate2D { + CLLocationCoordinate2D(latitude: latitude, longitude: longitude) + } +} +#endif diff --git a/Tests/ParseSwiftTests/ParseGeoPointTests.swift b/Tests/ParseSwiftTests/ParseGeoPointTests.swift index 7b1548b87..05121994f 100644 --- a/Tests/ParseSwiftTests/ParseGeoPointTests.swift +++ b/Tests/ParseSwiftTests/ParseGeoPointTests.swift @@ -53,6 +53,27 @@ class ParseGeoPointTests: XCTestCase { XCTAssertEqual(geoPoint.latitude, location.coordinate.latitude) XCTAssertEqual(geoPoint.longitude, location.coordinate.longitude) } + + func testGeoPointFromLocationCoordinate2D() throws { + let location = CLLocationCoordinate2D(latitude: 10.0, longitude: 20.0) + let geoPoint = try ParseGeoPoint(coordinate: location) + XCTAssertEqual(geoPoint.latitude, location.latitude) + XCTAssertEqual(geoPoint.longitude, location.longitude) + } + + func testToCLLocation() throws { + let point = try ParseGeoPoint(latitude: 10, longitude: 20) + let location = point.toCLLocation() + XCTAssertEqual(point.latitude, location.coordinate.latitude) + XCTAssertEqual(point.longitude, location.coordinate.longitude) + } + + func testToCLLocationCoordinate2D() throws { + let point = try ParseGeoPoint(latitude: 10, longitude: 20) + let location = point.toCLLocationCoordinate2D() + XCTAssertEqual(point.latitude, location.latitude) + XCTAssertEqual(point.longitude, location.longitude) + } #endif func testGeoPointEncoding() throws { @@ -215,4 +236,5 @@ class ParseGeoPointTests: XCTestCase { XCTAssertTrue(point.debugDescription.contains("10")) XCTAssertTrue(point.debugDescription.contains("20")) } + }