Skip to content

Commit

Permalink
refactor: Address Swift 5.8 warnings (#90)
Browse files Browse the repository at this point in the history
* refactor: Address Swift 5.8 warnings

* fix one test suite

* refactor all tests

* nits

* fix some tests

* Update linux to latest

* fix linux tests

* nits

* nit

* modify some tests

* move

* fix broken tests

* fixes

* fix tests on macOS

* fix anon tests

* fix linux tests

* lint

* add changelog

* skip test if needed
  • Loading branch information
cbaker6 committed Apr 4, 2023
1 parent a790bb7 commit 088e420
Show file tree
Hide file tree
Showing 37 changed files with 1,615 additions and 959 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ jobs:

linux:
timeout-minutes: 10
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: sersoft-gmbh/SwiftyActions@v2
Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
# Parse-Swift Changelog

### main
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.4.0...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.4.1...main), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/main/documentation/parseswift)
* _Contributing to this repo? Add info about your change here to be included in the next release_

### 5.4.1
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.4.0...5.4.1), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.4.1/documentation/parseswift)

__Fixes__
* Refactor test suite and code for Swift 5.8. Removes a number of warnings that show up in Xcode 14.3 ([#90](https://github.com/netreconlab/Parse-Swift/pull/90)), thanks to [Corey Baker](https://github.com/cbaker6).

### 5.4.0
[Full Changelog](https://github.com/netreconlab/Parse-Swift/compare/5.3.3...5.4.0), [Documentation](https://swiftpackageindex.com/netreconlab/Parse-Swift/5.4.0/documentation/parseswift)

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ import PackageDescription
let package = Package(
name: "YOUR_PROJECT_NAME",
dependencies: [
.package(url: "https://github.com/netreconlab/Parse-Swift", .upToNextMajor(from: "5.4.0")),
.package(url: "https://github.com/netreconlab/Parse-Swift", .upToNextMajor(from: "5.4.1")),
]
)
```
Expand Down
2 changes: 1 addition & 1 deletion Sources/ParseSwift/ParseConstants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

enum ParseConstants {
static let sdk = "swift"
static let version = "5.4.0"
static let version = "5.4.1"
static let fileManagementDirectory = "parse/"
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
static let fileManagementLibraryDirectory = "Library/"
Expand Down
17 changes: 15 additions & 2 deletions Sources/ParseSwift/Storage/KeychainStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,11 @@ extension KeychainStore {
return nil
}
do {
return try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? T
do {
return try NSKeyedUnarchiver.unarchivedObject(ofClass: NSString.self, from: data) as? T
} catch {
return try NSKeyedUnarchiver.unarchivedObject(ofClass: NSDictionary.self, from: data) as? T
}
} catch {
return nil
}
Expand All @@ -390,7 +394,16 @@ extension KeychainStore {
return removeObjectObjectiveC(forKey: key)
}
do {
let data = try NSKeyedArchiver.archivedData(withRootObject: object, requiringSecureCoding: false)
let data: Data!
if let stringObject = object as? String {
data = try NSKeyedArchiver.archivedData(withRootObject: stringObject as NSString,
requiringSecureCoding: false)
} else if let dictionaryObject = object as? [String: String] {
data = try NSKeyedArchiver.archivedData(withRootObject: dictionaryObject as NSDictionary,
requiringSecureCoding: false)
} else {
data = try NSKeyedArchiver.archivedData(withRootObject: object, requiringSecureCoding: false)
}
try set(data,
forKey: key,
useObjectiveCKeychain: true,
Expand Down
24 changes: 8 additions & 16 deletions Sources/ParseSwift/Storage/ParseFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,14 @@ extension ParseFileManager {
}
}

func removeDirectoryContents(_ path: URL, completion: @escaping(Error?) -> Void) {
synchronizationQueue.async {
do {
let contents = try FileManager.default.contentsOfDirectory(atPath: path.path)
if contents.count == 0 {
completion(nil)
return
}
try contents.forEach {
let filePath = path.appendingPathComponent($0)
try FileManager.default.removeItem(at: filePath)
}
completion(nil)
} catch {
completion(error)
}
func removeDirectoryContents(_ path: URL) throws {
let contents = try FileManager.default.contentsOfDirectory(atPath: path.path)
guard contents.count > 0 else {
return
}
try contents.forEach {
let filePath = path.appendingPathComponent($0)
try FileManager.default.removeItem(at: filePath)
}
}
}
Expand Down
32 changes: 32 additions & 0 deletions Tests/ParseSwiftTests/APICommandMultipleAttemptsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
}
}
}
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
await fulfillment(of: [expectation1], timeout: 20.0)
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
wait(for: [expectation1], timeout: 20.0)
#endif
}

func testErrorHTTPReturns400NoDataFromServer() async throws {
Expand All @@ -138,7 +142,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
expectation1.fulfill()
}
}
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
await fulfillment(of: [expectation1], timeout: 20.0)
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
wait(for: [expectation1], timeout: 20.0)
#endif
}

func testErrorHTTP429JSONInterval() async throws {
Expand Down Expand Up @@ -193,7 +201,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
}
}
}
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
await fulfillment(of: [expectation1], timeout: 20.0)
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
wait(for: [expectation1], timeout: 20.0)
#endif
}

func testErrorHTTP429JSONDate() async throws {
Expand Down Expand Up @@ -256,7 +268,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
}
}
}
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
await fulfillment(of: [expectation1], timeout: 20.0)
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
wait(for: [expectation1], timeout: 20.0)
#endif
}

func testErrorHTTP429JSONNoHeader() async throws {
Expand Down Expand Up @@ -308,7 +324,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
}
}
}
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
await fulfillment(of: [expectation1], timeout: 20.0)
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
wait(for: [expectation1], timeout: 20.0)
#endif
}

func testErrorHTTP503JSONInterval() async throws {
Expand Down Expand Up @@ -363,7 +383,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
}
}
}
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
await fulfillment(of: [expectation1], timeout: 20.0)
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
wait(for: [expectation1], timeout: 20.0)
#endif
}

func testErrorHTTP503JSONDate() async throws {
Expand Down Expand Up @@ -426,7 +450,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
}
}
}
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
await fulfillment(of: [expectation1], timeout: 20.0)
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
wait(for: [expectation1], timeout: 20.0)
#endif
}

func testErrorHTTP503JSONNoHeader() async throws {
Expand Down Expand Up @@ -478,6 +506,10 @@ class APICommandMultipleAttemptsTests: XCTestCase {
}
}
}
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
await fulfillment(of: [expectation1], timeout: 20.0)
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
wait(for: [expectation1], timeout: 20.0)
#endif
}
}
6 changes: 1 addition & 5 deletions Tests/ParseSwiftTests/IOS13Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ class IOS13Tests: XCTestCase {
}

let directory2 = try ParseFileManager.downloadDirectory()
let expectation2 = XCTestExpectation(description: "Delete files2")
fileManager.removeDirectoryContents(directory2) { _ in
expectation2.fulfill()
}
wait(for: [expectation2], timeout: 20.0)
try? fileManager.removeDirectoryContents(directory2)
}

func testSaveCommand() async throws {
Expand Down
Loading

0 comments on commit 088e420

Please sign in to comment.