Skip to content

Commit 088e420

Browse files
authored
refactor: Address Swift 5.8 warnings (#90)
* 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
1 parent a790bb7 commit 088e420

37 files changed

+1615
-959
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ jobs:
186186

187187
linux:
188188
timeout-minutes: 10
189-
runs-on: ubuntu-18.04
189+
runs-on: ubuntu-latest
190190
steps:
191191
- uses: actions/checkout@v3
192192
- uses: sersoft-gmbh/SwiftyActions@v2

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
# Parse-Swift Changelog
33

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

8+
### 5.4.1
9+
[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)
10+
11+
__Fixes__
12+
* 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).
13+
814
### 5.4.0
915
[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)
1016

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ import PackageDescription
7474
let package = Package(
7575
name: "YOUR_PROJECT_NAME",
7676
dependencies: [
77-
.package(url: "https://github.com/netreconlab/Parse-Swift", .upToNextMajor(from: "5.4.0")),
77+
.package(url: "https://github.com/netreconlab/Parse-Swift", .upToNextMajor(from: "5.4.1")),
7878
]
7979
)
8080
```

Sources/ParseSwift/ParseConstants.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Foundation
1010

1111
enum ParseConstants {
1212
static let sdk = "swift"
13-
static let version = "5.4.0"
13+
static let version = "5.4.1"
1414
static let fileManagementDirectory = "parse/"
1515
static let fileManagementPrivateDocumentsDirectory = "Private Documents/"
1616
static let fileManagementLibraryDirectory = "Library/"

Sources/ParseSwift/Storage/KeychainStore.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,11 @@ extension KeychainStore {
373373
return nil
374374
}
375375
do {
376-
return try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? T
376+
do {
377+
return try NSKeyedUnarchiver.unarchivedObject(ofClass: NSString.self, from: data) as? T
378+
} catch {
379+
return try NSKeyedUnarchiver.unarchivedObject(ofClass: NSDictionary.self, from: data) as? T
380+
}
377381
} catch {
378382
return nil
379383
}
@@ -390,7 +394,16 @@ extension KeychainStore {
390394
return removeObjectObjectiveC(forKey: key)
391395
}
392396
do {
393-
let data = try NSKeyedArchiver.archivedData(withRootObject: object, requiringSecureCoding: false)
397+
let data: Data!
398+
if let stringObject = object as? String {
399+
data = try NSKeyedArchiver.archivedData(withRootObject: stringObject as NSString,
400+
requiringSecureCoding: false)
401+
} else if let dictionaryObject = object as? [String: String] {
402+
data = try NSKeyedArchiver.archivedData(withRootObject: dictionaryObject as NSDictionary,
403+
requiringSecureCoding: false)
404+
} else {
405+
data = try NSKeyedArchiver.archivedData(withRootObject: object, requiringSecureCoding: false)
406+
}
394407
try set(data,
395408
forKey: key,
396409
useObjectiveCKeychain: true,

Sources/ParseSwift/Storage/ParseFileManager.swift

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -190,22 +190,14 @@ extension ParseFileManager {
190190
}
191191
}
192192

193-
func removeDirectoryContents(_ path: URL, completion: @escaping(Error?) -> Void) {
194-
synchronizationQueue.async {
195-
do {
196-
let contents = try FileManager.default.contentsOfDirectory(atPath: path.path)
197-
if contents.count == 0 {
198-
completion(nil)
199-
return
200-
}
201-
try contents.forEach {
202-
let filePath = path.appendingPathComponent($0)
203-
try FileManager.default.removeItem(at: filePath)
204-
}
205-
completion(nil)
206-
} catch {
207-
completion(error)
208-
}
193+
func removeDirectoryContents(_ path: URL) throws {
194+
let contents = try FileManager.default.contentsOfDirectory(atPath: path.path)
195+
guard contents.count > 0 else {
196+
return
197+
}
198+
try contents.forEach {
199+
let filePath = path.appendingPathComponent($0)
200+
try FileManager.default.removeItem(at: filePath)
209201
}
210202
}
211203
}

Tests/ParseSwiftTests/APICommandMultipleAttemptsTests.swift

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
111111
}
112112
}
113113
}
114+
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
115+
await fulfillment(of: [expectation1], timeout: 20.0)
116+
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
114117
wait(for: [expectation1], timeout: 20.0)
118+
#endif
115119
}
116120

117121
func testErrorHTTPReturns400NoDataFromServer() async throws {
@@ -138,7 +142,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
138142
expectation1.fulfill()
139143
}
140144
}
145+
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
146+
await fulfillment(of: [expectation1], timeout: 20.0)
147+
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
141148
wait(for: [expectation1], timeout: 20.0)
149+
#endif
142150
}
143151

144152
func testErrorHTTP429JSONInterval() async throws {
@@ -193,7 +201,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
193201
}
194202
}
195203
}
204+
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
205+
await fulfillment(of: [expectation1], timeout: 20.0)
206+
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
196207
wait(for: [expectation1], timeout: 20.0)
208+
#endif
197209
}
198210

199211
func testErrorHTTP429JSONDate() async throws {
@@ -256,7 +268,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
256268
}
257269
}
258270
}
271+
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
272+
await fulfillment(of: [expectation1], timeout: 20.0)
273+
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
259274
wait(for: [expectation1], timeout: 20.0)
275+
#endif
260276
}
261277

262278
func testErrorHTTP429JSONNoHeader() async throws {
@@ -308,7 +324,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
308324
}
309325
}
310326
}
327+
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
328+
await fulfillment(of: [expectation1], timeout: 20.0)
329+
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
311330
wait(for: [expectation1], timeout: 20.0)
331+
#endif
312332
}
313333

314334
func testErrorHTTP503JSONInterval() async throws {
@@ -363,7 +383,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
363383
}
364384
}
365385
}
386+
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
387+
await fulfillment(of: [expectation1], timeout: 20.0)
388+
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
366389
wait(for: [expectation1], timeout: 20.0)
390+
#endif
367391
}
368392

369393
func testErrorHTTP503JSONDate() async throws {
@@ -426,7 +450,11 @@ class APICommandMultipleAttemptsTests: XCTestCase {
426450
}
427451
}
428452
}
453+
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
454+
await fulfillment(of: [expectation1], timeout: 20.0)
455+
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
429456
wait(for: [expectation1], timeout: 20.0)
457+
#endif
430458
}
431459

432460
func testErrorHTTP503JSONNoHeader() async throws {
@@ -478,6 +506,10 @@ class APICommandMultipleAttemptsTests: XCTestCase {
478506
}
479507
}
480508
}
509+
#if compiler(>=5.8.0) && !os(Linux) && !os(Android) && !os(Windows)
510+
await fulfillment(of: [expectation1], timeout: 20.0)
511+
#elseif compiler(<5.8.0) && !os(iOS) && !os(tvOS)
481512
wait(for: [expectation1], timeout: 20.0)
513+
#endif
482514
}
483515
}

Tests/ParseSwiftTests/IOS13Tests.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,7 @@ class IOS13Tests: XCTestCase {
8181
}
8282

8383
let directory2 = try ParseFileManager.downloadDirectory()
84-
let expectation2 = XCTestExpectation(description: "Delete files2")
85-
fileManager.removeDirectoryContents(directory2) { _ in
86-
expectation2.fulfill()
87-
}
88-
wait(for: [expectation2], timeout: 20.0)
84+
try? fileManager.removeDirectoryContents(directory2)
8985
}
9086

9187
func testSaveCommand() async throws {

0 commit comments

Comments
 (0)