Skip to content

Commit 96cdfa8

Browse files
Merge pull request #81 from ably-labs/use-main-ably-cocoa
Use `main` branch of ably-cocoa
2 parents 4da8e42 + 7b3c97f commit 96cdfa8

File tree

8 files changed

+51
-17
lines changed

8 files changed

+51
-17
lines changed

AblyChat.xcworkspace/xcshareddata/swiftpm/Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/AblyChatExample/Mocks/MockRealtime.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ final class MockRealtime: NSObject, RealtimeClientProtocol, Sendable {
4444
fatalError("Not implemented")
4545
}
4646

47+
var properties: ARTChannelProperties {
48+
fatalError("Not implemented")
49+
}
50+
4751
func attach() {
4852
fatalError("Not implemented")
4953
}
@@ -211,4 +215,8 @@ final class MockRealtime: NSObject, RealtimeClientProtocol, Sendable {
211215
func close() {
212216
fatalError("Not implemented")
213217
}
218+
219+
func request(_: String, path _: String, params _: [String: String]?, body _: Any?, headers _: [String: String]?, callback _: @escaping ARTHTTPPaginatedCallback) throws {
220+
fatalError("Not implemented")
221+
}
214222
}

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ let package = Package(
2020
dependencies: [
2121
.package(
2222
url: "https://github.com/ably/ably-cocoa",
23-
from: "1.2.0"
23+
// TODO: Switch back to using a tag (https://github.com/ably-labs/ably-chat-swift/issues/80)
24+
branch: "main"
2425
),
2526
.package(
2627
url: "https://github.com/apple/swift-argument-parser",
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import Ably
22

3-
// TODO: remove "@unchecked Sendable" once https://github.com/ably/ably-cocoa/issues/1962 done
3+
extension ARTRealtime: RealtimeClientProtocol {}
44

5-
// This @retroactive is needed to silence the Swift 6 compiler error "extension declares a conformance of imported type 'ARTRealtimeChannels' to imported protocol 'Sendable'; this will not behave correctly if the owners of 'Ably' introduce this conformance in the future (…) add '@retroactive' to silence this warning". I don’t fully understand the implications of this but don’t really mind since both libraries are in our control.
6-
extension ARTRealtime: RealtimeClientProtocol, @retroactive @unchecked Sendable {}
5+
extension ARTRealtimeChannels: RealtimeChannelsProtocol {}
76

8-
extension ARTRealtimeChannels: RealtimeChannelsProtocol, @retroactive @unchecked Sendable {}
9-
10-
extension ARTRealtimeChannel: RealtimeChannelProtocol, @retroactive @unchecked Sendable {}
7+
extension ARTRealtimeChannel: RealtimeChannelProtocol {}

Sources/BuildTool/BuildTool.swift

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ struct Lint: AsyncParsableCommand {
9696
enum Error: Swift.Error {
9797
case malformedSwiftVersionFile
9898
case malformedPackageManifestFile
99+
case malformedPackageLockfile
99100
case mismatchedVersions(swiftVersionFileVersion: String, packageManifestFileVersion: String)
100101
case packageLockfilesHaveDifferentContents(paths: [String])
101102
}
@@ -152,12 +153,14 @@ struct Lint: AsyncParsableCommand {
152153
}
153154

154155
/// Checks that the SPM-managed Package.resolved matches the Xcode-managed one. (I still don’t fully understand _why_ there are two files).
156+
///
157+
/// Ignores the `originHash` property of the Package.resolved file, because this property seems to frequently be different between the SPM version and the Xcode version, and I don’t know enough about SPM to know what this property means or whether there’s a reproducible way to get them to match.
155158
func comparePackageLockfiles() async throws {
156159
let lockfilePaths = ["Package.resolved", "AblyChat.xcworkspace/xcshareddata/swiftpm/Package.resolved"]
157-
let lockfileContents = try await withThrowingTaskGroup(of: String.self) { group in
160+
let lockfileContents = try await withThrowingTaskGroup(of: Data.self) { group in
158161
for lockfilePath in lockfilePaths {
159162
group.addTask {
160-
try await loadUTF8StringFromFile(at: lockfilePath)
163+
try await loadDataFromFile(at: lockfilePath)
161164
}
162165
}
163166

@@ -166,13 +169,30 @@ struct Lint: AsyncParsableCommand {
166169
}
167170
}
168171

169-
if Set(lockfileContents).count > 1 {
172+
// Remove the `originHash` property from the Package.resolved contents before comparing (for reasons described above).
173+
let lockfileContentsWeCareAbout = try lockfileContents.map { data in
174+
guard var dictionary = try JSONSerialization.jsonObject(with: data) as? [String: Any] else {
175+
throw Error.malformedPackageLockfile
176+
}
177+
178+
dictionary.removeValue(forKey: "originHash")
179+
180+
// We use .sortedKeys to get a canonical JSON encoding for comparison.
181+
return try JSONSerialization.data(withJSONObject: dictionary, options: .sortedKeys)
182+
}
183+
184+
if Set(lockfileContentsWeCareAbout).count > 1 {
170185
throw Error.packageLockfilesHaveDifferentContents(paths: lockfilePaths)
171186
}
172187
}
173188

174-
private func loadUTF8StringFromFile(at path: String) async throws -> String {
189+
private func loadDataFromFile(at path: String) async throws -> Data {
175190
let (data, _) = try await URLSession.shared.data(from: .init(filePath: path))
191+
return data
192+
}
193+
194+
private func loadUTF8StringFromFile(at path: String) async throws -> String {
195+
let data = try await loadDataFromFile(at: path)
176196
return try String(data: data, encoding: .utf8)
177197
}
178198
}

Tests/AblyChatTests/Mocks/MockRealtime.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,8 @@ final class MockRealtime: NSObject, RealtimeClientProtocol, Sendable {
6262
func close() {
6363
fatalError("Not implemented")
6464
}
65+
66+
func request(_: String, path _: String, params _: [String: String]?, body _: Any?, headers _: [String: String]?, callback _: @escaping ARTHTTPPaginatedCallback) throws {
67+
fatalError("Not implemented")
68+
}
6569
}

Tests/AblyChatTests/Mocks/MockRealtimeChannel.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ final class MockRealtimeChannel: NSObject, RealtimeChannelProtocol {
5454
fatalError("Not implemented")
5555
}
5656

57+
var properties: ARTChannelProperties {
58+
fatalError("Not implemented")
59+
}
60+
5761
func attach() {
5862
fatalError("Not implemented")
5963
}

0 commit comments

Comments
 (0)