Skip to content

Commit 6a932e4

Browse files
committed
Fix build for Swift 6
1 parent 9b1249a commit 6a932e4

File tree

4 files changed

+59
-15
lines changed

4 files changed

+59
-15
lines changed

Sources/LiveViewNative/Coordinators/LiveSessionCoordinator.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
118118
try await prev.last?.coordinator.disconnect()
119119
let liveChannel = try! await self.liveSocket!.joinLiveviewChannel(
120120
.some([
121-
"_format": .str(string: Self.platform),
122-
"_interface": Self.platformParams
121+
"_format": .str(string: LiveSessionParameters.platform),
122+
"_interface": .object(object: LiveSessionParameters.platformParams)
123123
]),
124124
next.last!.url.absoluteString
125125
)
@@ -130,8 +130,8 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
130130
try await prev.last?.coordinator.disconnect()
131131
let liveChannel = try! await self.liveSocket!.joinLiveviewChannel(
132132
.some([
133-
"_format": .str(string: Self.platform),
134-
"_interface": Self.platformParams
133+
"_format": .str(string: LiveSessionParameters.platform),
134+
"_interface": .object(object: LiveSessionParameters.platformParams)
135135
]),
136136
next.last!.url.absoluteString
137137
)
@@ -195,15 +195,15 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
195195
let liveChannel = try! await self.liveSocket!.joinLiveviewChannel(
196196
.some([
197197
"_format": .str(string: LiveSessionParameters.platform),
198-
"_interface": LiveSessionParameters.platformParams
198+
"_interface": .object(object: LiveSessionParameters.platformParams)
199199
]),
200200
nil
201201
)
202202

203203
self.rootLayout = self.liveSocket!.deadRender()
204204
let styleURLs = self.liveSocket!.styleUrls()
205205

206-
self.stylesheet = try! await withThrowingTaskGroup(of: Stylesheet<R>.self) { group in
206+
self.stylesheet = try! await withThrowingTaskGroup(of: Stylesheet<R>.self) { @Sendable group in
207207
for style in styleURLs {
208208
guard let url = await URL(string: style, relativeTo: self.url)
209209
else { continue }
@@ -216,7 +216,7 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
216216
}
217217

218218
return try await group.reduce(Stylesheet<R>(content: [], classes: [:])) { result, next in
219-
return result.merge(with: next)
219+
return await result.merge(with: next)
220220
}
221221
}
222222

@@ -233,7 +233,7 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
233233
func bindLiveReloadListener() {
234234
let eventListener = self.liveReloadChannel!.channel().eventStream()
235235
self.liveReloadListener = eventListener
236-
self.liveReloadListenerLoop = Task { [weak self] in
236+
self.liveReloadListenerLoop = Task { @MainActor [weak self] in
237237
for try await event in eventListener {
238238
guard let self else { return }
239239
switch event.event {
@@ -349,8 +349,8 @@ public class LiveSessionCoordinator<R: RootRegistry>: ObservableObject {
349349
@MainActor
350350
enum LiveSessionParameters {
351351
static var platform: String { "swiftui" }
352-
static var platformParams: LiveViewNativeCore.Json {
353-
.object(object: [
352+
static var platformParams: [String:LiveViewNativeCore.Json] {
353+
[
354354
"app_version": .str(string: getAppVersion()),
355355
"app_build": .str(string: getAppBuild()),
356356
"bundle_id": .str(string: getBundleID()),
@@ -359,7 +359,7 @@ enum LiveSessionParameters {
359359
"target": .str(string: getTarget()),
360360
"l10n": getLocalization(),
361361
"i18n": getInternationalization()
362-
])
362+
]
363363
}
364364

365365
private static func getAppVersion() -> String {
@@ -454,11 +454,11 @@ enum LiveSessionParameters {
454454
/// Create a nested structure of query items.
455455
///
456456
/// `_root[key][nested_key]=value`
457-
func queryParameters(for object: [String:Any]) -> [(name: String, value: String?)] {
457+
func queryParameters(for object: [String:Json]) -> [(name: String, value: String?)] {
458458
object.reduce(into: [(name: String, value: String?)]()) { (result, pair) in
459459
if let value = pair.value as? String {
460460
result.append((name: "[\(pair.key)]", value: value))
461-
} else if let nested = pair.value as? [String:Any] {
461+
} else if case let .object(nested) = pair.value {
462462
result.append(contentsOf: queryParameters(for: nested).map {
463463
return (name: "[\(pair.key)]\($0.name)", value: $0.value)
464464
})

Sources/LiveViewNative/Coordinators/LiveViewCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public class LiveViewCoordinator<R: RootRegistry>: ObservableObject {
289289
let channel = liveChannel.channel()
290290
self.channel = channel
291291

292-
statusListenerLoop = Task { [weak self] in
292+
statusListenerLoop = Task { @MainActor [weak self] in
293293
for try await status in channel.statusStream() {
294294
guard let self else { return }
295295
self.internalState = switch status {

Sources/LiveViewNative/ViewModel.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public class FormModel: ObservableObject, CustomDebugStringConvertible {
6464
}
6565

6666
@_spi(LiveForm) public func updateFromElement(_ element: ElementNode, submitAction: @escaping () -> ()) {
67+
let pushEventImpl = pushEventImpl!
6768
self.changeEvent = element.attributeValue(for: .init(name: "phx-change")).flatMap({ event in
6869
{ value in
6970
Task {
@@ -161,7 +162,7 @@ public class FormModel: ObservableObject, CustomDebugStringConvertible {
161162
_ = try await pushEventImpl("form", event, try buildFormQuery(), nil)
162163
}
163164

164-
public var debugDescription: String {
165+
public nonisolated var debugDescription: String {
165166
return "FormModel(element: #\(elementID), id: \(ObjectIdentifier(self))"
166167
}
167168

Sources/LiveViewNative/__CoreExtensions.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@
88
import LiveViewNativeCore
99
import Foundation
1010

11+
extension LiveViewNativeCore.ChannelStatus: @unchecked Sendable {}
12+
extension LiveViewNativeCore.PhoenixEvent: @unchecked Sendable {}
13+
extension LiveViewNativeCore.Event: @unchecked Sendable {}
14+
extension LiveViewNativeCore.Json: @unchecked Sendable {}
15+
extension LiveViewNativeCore.Payload: @unchecked Sendable {}
16+
extension LiveViewNativeCore.EventPayload: @unchecked Sendable {}
17+
18+
extension LiveViewNativeCore.LiveChannel: @unchecked Sendable {}
19+
extension LiveViewNativeCore.LiveSocket: @unchecked Sendable {}
20+
21+
extension LiveViewNativeCore.Events: @unchecked Sendable {}
22+
extension LiveViewNativeCore.ChannelStatuses: @unchecked Sendable {}
23+
1124
extension Node: Identifiable {
1225
public var id: NodeRef {
1326
self.id()
@@ -767,6 +780,11 @@ private extension __JsonEncoder {
767780

768781
// We can pop because the closure encoded something.
769782
return self.storage.popReference()
783+
@unknown default:
784+
try with(path: codingPath + (additionalKey.map({ [$0] }) ?? [])) {
785+
try date.encode(to: self)
786+
}
787+
return self.storage.popReference()
770788
}
771789
}
772790

@@ -814,6 +832,23 @@ private extension __JsonEncoder {
814832
}
815833

816834
// We can pop because the closure encoded something.
835+
return self.storage.popReference()
836+
@unknown default:
837+
let depth = self.storage.count
838+
do {
839+
try with(path: codingPath + (additionalKey.map({ [$0] }) ?? [])) {
840+
try data.encode(to: self)
841+
}
842+
} catch {
843+
// If the value pushed a container before throwing, pop it back off to restore state.
844+
// This shouldn't be possible for Data (which encodes as an array of bytes), but it can't hurt to catch a failure.
845+
if self.storage.count > depth {
846+
let _ = self.storage.popReference()
847+
}
848+
849+
throw error
850+
}
851+
817852
return self.storage.popReference()
818853
}
819854
}
@@ -1220,6 +1255,10 @@ extension __JsonDecoder {
12201255
return try with(value: value, path: codingPath + (additionalKey.map({ [$0] }) ?? [])) {
12211256
try closure(self)
12221257
}
1258+
@unknown default:
1259+
return try with(value: value, path: codingPath + (additionalKey.map({ [$0] }) ?? [])) {
1260+
try Date(from: self)
1261+
}
12231262
}
12241263
}
12251264

@@ -1243,6 +1282,10 @@ extension __JsonDecoder {
12431282
return try with(value: value, path: codingPath + (additionalKey.map({ [$0] }) ?? [])) {
12441283
try closure(self)
12451284
}
1285+
@unknown default:
1286+
return try with(value: value, path: codingPath + (additionalKey.map({ [$0] }) ?? [])) {
1287+
try Data(from: self)
1288+
}
12461289
}
12471290
}
12481291

0 commit comments

Comments
 (0)