diff --git a/connections/swift/NearbyConnections/Example/iOS Example/ConnectedView.swift b/connections/swift/NearbyConnections/Example/iOS Example/ConnectedView.swift index 57dfa6f0..9950a379 100644 --- a/connections/swift/NearbyConnections/Example/iOS Example/ConnectedView.swift +++ b/connections/swift/NearbyConnections/Example/iOS Example/ConnectedView.swift @@ -20,7 +20,7 @@ struct ConnectedView: View { var connection: ConnectedEndpoint var onSendBytes : () -> () var onDisconnect : () -> () - + var body: some View { Section("Connection Actions") { Button("Send Bytes") { diff --git a/connections/swift/NearbyConnections/Example/iOS Example/ConnectionRequestView.swift b/connections/swift/NearbyConnections/Example/iOS Example/ConnectionRequestView.swift index 9f5f59a9..5189486e 100644 --- a/connections/swift/NearbyConnections/Example/iOS Example/ConnectionRequestView.swift +++ b/connections/swift/NearbyConnections/Example/iOS Example/ConnectionRequestView.swift @@ -20,9 +20,9 @@ struct ConnectionRequestView: View { var connectionRequest: ConnectionRequest var onAcceptConnection : () -> () var onRejectConnection : () -> () - + @State private var hasResponded = false - + var body: some View { Section(footer: Text("Security code: \(connectionRequest.pin)")) { Button("Accept") { diff --git a/connections/swift/NearbyConnections/Example/iOS Example/ContentView.swift b/connections/swift/NearbyConnections/Example/iOS Example/ContentView.swift index 651df340..ab7ff980 100644 --- a/connections/swift/NearbyConnections/Example/iOS Example/ContentView.swift +++ b/connections/swift/NearbyConnections/Example/iOS Example/ContentView.swift @@ -19,7 +19,7 @@ import NearbyConnections struct ContentView: View { @EnvironmentObject private var model: Model - + let strategies: [Strategy: String] = [ .cluster: "Cluster", .pointToPoint: "Point to Point", diff --git a/connections/swift/NearbyConnections/Example/iOS Example/DiscoveredEndpointView.swift b/connections/swift/NearbyConnections/Example/iOS Example/DiscoveredEndpointView.swift index c446e1ab..75087992 100644 --- a/connections/swift/NearbyConnections/Example/iOS Example/DiscoveredEndpointView.swift +++ b/connections/swift/NearbyConnections/Example/iOS Example/DiscoveredEndpointView.swift @@ -19,9 +19,9 @@ import SwiftUI struct DiscoveredEndpointView: View { var endpoint: DiscoveredEndpoint var onRequestConnection : () -> () - + @State private var hasResponded = false - + var body: some View { Section { Button("Connect") { diff --git a/connections/swift/NearbyConnections/Example/iOS Example/EndpointDetail.swift b/connections/swift/NearbyConnections/Example/iOS Example/EndpointDetail.swift index 7875082f..dcfd06ae 100644 --- a/connections/swift/NearbyConnections/Example/iOS Example/EndpointDetail.swift +++ b/connections/swift/NearbyConnections/Example/iOS Example/EndpointDetail.swift @@ -18,22 +18,22 @@ import SwiftUI struct EndpointDetail: View { var endpointID: String - + @EnvironmentObject private var model: Model - + var body: some View { let endpoint = model.endpoints.first { $0.id == endpointID } let connectionRequest = model.requests.first { $0.id == endpointID } let connection = model.connections.first { $0.id == endpointID } let name = connectionRequest?.endpointName ?? connection?.endpointName ?? endpoint?.endpointName - + Form { if let endpoint { DiscoveredEndpointView(endpoint: endpoint, onRequestConnection: { model.requestConnection(to: endpointID) }) } - + if let connectionRequest { ConnectionRequestView(connectionRequest: connectionRequest, onAcceptConnection: { connectionRequest.shouldAccept(true) diff --git a/connections/swift/NearbyConnections/Example/iOS Example/HelloConnectionsApp.swift b/connections/swift/NearbyConnections/Example/iOS Example/HelloConnectionsApp.swift index 5778c0e9..0e67a8d5 100644 --- a/connections/swift/NearbyConnections/Example/iOS Example/HelloConnectionsApp.swift +++ b/connections/swift/NearbyConnections/Example/iOS Example/HelloConnectionsApp.swift @@ -19,7 +19,7 @@ import SwiftUI @main struct HelloConnectionsApp: App { @StateObject private var model = Model() - + var body: some Scene { WindowGroup { ContentView() diff --git a/connections/swift/NearbyConnections/Example/iOS Example/Model/Config.swift b/connections/swift/NearbyConnections/Example/iOS Example/Model/Config.swift index 64165f8b..49d4a3b8 100644 --- a/connections/swift/NearbyConnections/Example/iOS Example/Model/Config.swift +++ b/connections/swift/NearbyConnections/Example/iOS Example/Model/Config.swift @@ -26,7 +26,7 @@ class Config { static let defaultAdvertisingState = false static let defaultDiscoveryState = false static let bytePayload = "hello world" - + #if os(iOS) || os(watchOS) || os(tvOS) static let defaultEndpointName = UIDevice.current.name #elseif os(macOS) diff --git a/connections/swift/NearbyConnections/Example/iOS Example/Model/Model.swift b/connections/swift/NearbyConnections/Example/iOS Example/Model/Model.swift index 8c4a10b1..c50740e9 100644 --- a/connections/swift/NearbyConnections/Example/iOS Example/Model/Model.swift +++ b/connections/swift/NearbyConnections/Example/iOS Example/Model/Model.swift @@ -39,20 +39,20 @@ class Model: ObservableObject { invalidateDiscovery() } } - + @Published private(set) var requests: [ConnectionRequest] = [] @Published private(set) var connections: [ConnectedEndpoint] = [] @Published private(set) var endpoints: [DiscoveredEndpoint] = [] - + var connectionManager: ConnectionManager! var advertiser: Advertiser? var discoverer: Discoverer? - + init() { invalidateAdvertising() invalidateDiscovery() } - + private var isAdvertising = Config.defaultAdvertisingState private func invalidateAdvertising() { defer { @@ -66,12 +66,12 @@ class Model: ObservableObject { } connectionManager = ConnectionManager(serviceID: Config.serviceId, strategy: strategy) connectionManager.delegate = self - + advertiser = Advertiser(connectionManager: connectionManager) advertiser?.delegate = self advertiser?.startAdvertising(using: endpointName.data(using: .utf8)!) } - + private var isDiscovering = Config.defaultDiscoveryState private func invalidateDiscovery() { defer { @@ -85,20 +85,20 @@ class Model: ObservableObject { } connectionManager = ConnectionManager(serviceID: Config.serviceId, strategy: strategy) connectionManager.delegate = self - + discoverer = Discoverer(connectionManager: connectionManager) discoverer?.delegate = self discoverer?.startDiscovery() } - + func requestConnection(to endpointID: EndpointID) { discoverer?.requestConnection(to: endpointID, using: endpointName.data(using: .utf8)!) } - + func disconnect(from endpointID: EndpointID) { connectionManager.disconnect(from: endpointID) } - + func sendBytes(to endpointIDs: [EndpointID]) { let payloadID = PayloadID.unique() let token = connectionManager.send(Config.bytePayload.data(using: .utf8)!, to: endpointIDs, id: payloadID) @@ -126,7 +126,7 @@ extension Model: DiscovererDelegate { ) endpoints.insert(endpoint, at: 0) } - + func discoverer(_ discoverer: Discoverer, didLose endpointID: EndpointID) { guard let index = endpoints.firstIndex(where: { $0.id == endpointID }) else { return @@ -190,7 +190,7 @@ extension Model: ConnectionManagerDelegate { } connections[index].payloads.insert(payload, at: 0) } - + func connectionManager(_ connectionManager: ConnectionManager, didStartReceivingResourceWithID payloadID: PayloadID, from endpointID: EndpointID, at localURL: URL, withName name: String, cancellationToken token: CancellationToken) { let payload = Payload( id: payloadID, @@ -204,7 +204,7 @@ extension Model: ConnectionManagerDelegate { } connections[index].payloads.insert(payload, at: 0) } - + func connectionManager(_ connectionManager: ConnectionManager, didReceiveTransferUpdate update: TransferUpdate, from endpointID: EndpointID, forPayload payloadID: PayloadID) { guard let connectionIndex = connections.firstIndex(where: { $0.id == endpointID }), let payloadIndex = connections[connectionIndex].payloads.firstIndex(where: { $0.id == payloadID }) else { diff --git a/connections/swift/NearbyConnections/Example/iOS Example/Model/Payload.swift b/connections/swift/NearbyConnections/Example/iOS Example/Model/Payload.swift index a3eaf1d9..530c1dc0 100644 --- a/connections/swift/NearbyConnections/Example/iOS Example/Model/Payload.swift +++ b/connections/swift/NearbyConnections/Example/iOS Example/Model/Payload.swift @@ -23,7 +23,7 @@ struct Payload: Identifiable { var status: Status let isIncoming: Bool let cancellationToken: CancellationToken? - + enum PayloadType { case bytes, stream, file } diff --git a/connections/swift/NearbyConnections/Example/iOS Example/PayloadView.swift b/connections/swift/NearbyConnections/Example/iOS Example/PayloadView.swift index 5ec63b38..5157b8c0 100644 --- a/connections/swift/NearbyConnections/Example/iOS Example/PayloadView.swift +++ b/connections/swift/NearbyConnections/Example/iOS Example/PayloadView.swift @@ -18,7 +18,7 @@ import SwiftUI struct PayloadView: View { var payload: Payload - + var body: some View { HStack(alignment: .top) { Image(systemName: payload.isIncoming