From 3572ca7970dce638d2d7b3d08c82ca886ff6831e Mon Sep 17 00:00:00 2001 From: Guilherme Souza Date: Mon, 23 Sep 2024 07:56:52 -0300 Subject: [PATCH] docs: fix swift realtime samples (#29183) --- apps/docs/spec/supabase_swift_v2.yml | 152 +++++++++++++-------------- 1 file changed, 76 insertions(+), 76 deletions(-) diff --git a/apps/docs/spec/supabase_swift_v2.yml b/apps/docs/spec/supabase_swift_v2.yml index e98c309698c..65a99cf22fc 100644 --- a/apps/docs/spec/supabase_swift_v2.yml +++ b/apps/docs/spec/supabase_swift_v2.yml @@ -3611,27 +3611,25 @@ functions: isSpotlight: true code: | ```swift - let channel = await supabase.channel("room1") + let channel = supabase.channel("room1") - let broadcastStream = await channel.broadcastStream(event: "cursor-pos") + let broadcastStream = channel.broadcastStream(event: "cursor-pos") await channel.subscribe() Task { - for await message in broadcastMessage { - print("Cursor position received", message.payload) + for await message in broadcastStream { + print("Cursor position received", message) } } - Task { - await channel.broadcast( - event: "cursor-pos", - message: [ - "x": .double(.random(in: 0...1)), - "y": .double(.random(in: 0...1)) - ] - ) - } + await channel.broadcast( + event: "cursor-pos", + message: [ + "x": .double(.random(in: 0...1)), + "y": .double(.random(in: 0...1)) + ] + ) ``` - id: listen-to-broadcast-callback @@ -3639,10 +3637,10 @@ functions: isSpotlight: true code: | ```swift - let channel = await supabase.channel("room1") + let channel = supabase.channel("room1") - let subscription = await channel.onBroadcast(event: "cursor-pos") { message in - print("Cursor position received", message.payload) + let subscription = channel.onBroadcast(event: "cursor-pos") { message in + print("Cursor position received", message) } await channel.subscribe() @@ -3656,7 +3654,7 @@ functions: ) // remove subscription some time later - subscription.remove() + subscription.cancel() ``` - id: listen-to-presence-updates @@ -3667,9 +3665,9 @@ functions: let username: String } - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let presenceChange = await channel.presenceChange() + let presenceChange = channel.presenceChange() await channel.subscribe() @@ -3681,9 +3679,7 @@ functions: } // Send your own state - Task { - try await channel.track(PresenceState(username: "John")) - } + try await channel.track(PresenceState(username: "John")) - id: listen-to-presence-updates-callback name: Listen to presence updates using callback @@ -3693,11 +3689,15 @@ functions: let username: String } - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let subscription = await channel.onPresenceChange() { presence in - let joins = try presence.decodeJoins(as: PresenceState.self) - let leaves = try presence.decodeLeaves(as: PresenceState.self) + let subscription = channel.onPresenceChange() { presence in + do { + let joins = try presence.decodeJoins(as: PresenceState.self) + let leaves = try presence.decodeLeaves(as: PresenceState.self) + } catch { + // Handle decoding error + } } await channel.subscribe() @@ -3706,25 +3706,25 @@ functions: try await channel.track(PresenceState(username: "John")) // remove subscription some time later - subscription.remove() + subscription.cancel() ``` - id: listen-to-all-database-changes name: Listen to all database changes code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let changeStream = await channel.postgresChange(AnyAction.self, schema: "public") + let changeStream = channel.postgresChange(AnyAction.self, schema: "public") await channel.subscribe() for await change in changeStream { switch change { - case .delete(let action): print("Deleted: \(action.oldRecord)") - case .insert(let action): print("Inserted: \(action.record)") - case .select(let action): print("Selected: \(action.record)") - case .update(let action): print("Updated": \(action.oldRecord) with \(action.record)") + case .delete(let action): print("Deleted: \(action.oldRecord)") + case .insert(let action): print("Inserted: \(action.record)") + case .select(let action): print("Selected: \(action.record)") + case .update(let action): print("Updated: \(action.oldRecord) with \(action.record)") } } ``` @@ -3732,29 +3732,29 @@ functions: name: Listen to all database changes using callback code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let subscription = await channel.onPostgresChange(AnyAction.self, schema: "public") { change in + let subscription = channel.onPostgresChange(AnyAction.self, schema: "public") { change in switch change { - case .delete(let action): print("Deleted: \(action.oldRecord)") - case .insert(let action): print("Inserted: \(action.record)") - case .select(let action): print("Selected: \(action.record)") - case .update(let action): print("Updated": \(action.oldRecord) with \(action.record)") + case .delete(let action): print("Deleted: \(action.oldRecord)") + case .insert(let action): print("Inserted: \(action.record)") + case .select(let action): print("Selected: \(action.record)") + case .update(let action): print("Updated: \(action.oldRecord) with \(action.record)") } } await channel.subscribe() // remove subscription some time later - subscription.remove() + subscription.cancel() ``` - id: listen-to-a-specific-table name: Listen to a specific table code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let changeStream = await channel.postgresChange( + let changeStream = channel.postgresChange( AnyAction.self, schema: "public", table: "users" @@ -3767,7 +3767,7 @@ functions: case .delete(let action): print("Deleted: \(action.oldRecord)") case .insert(let action): print("Inserted: \(action.record)") case .select(let action): print("Selected: \(action.record)") - case .update(let action): print("Updated": \(action.oldRecord) with \(action.record)") + case .update(let action): print("Updated: \(action.oldRecord) with \(action.record)") } } ``` @@ -3775,34 +3775,34 @@ functions: name: Listen to a specific table using callback code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let subscription = await channel.onPostgresChange( - AnyAction.self, + let subscription = channel.onPostgresChange( + AnyAction.self, schema: "public", table: "users" - ) { change in + ) { change in switch change { - case .delete(let action): print("Deleted: \(action.oldRecord)") - case .insert(let action): print("Inserted: \(action.record)") - case .select(let action): print("Selected: \(action.record)") - case .update(let action): print("Updated": \(action.oldRecord) with \(action.record)") + case .delete(let action): print("Deleted: \(action.oldRecord)") + case .insert(let action): print("Inserted: \(action.record)") + case .select(let action): print("Selected: \(action.record)") + case .update(let action): print("Updated: \(action.oldRecord) with \(action.record)") } } await channel.subscribe() // remove subscription some time later - subscription.remove() + subscription.cancel() ``` - id: listen-to-inserts name: Listen to inserts code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let insertions = await channel.postgresChange( - InsertAction.self, + let insertions = channel.postgresChange( + InsertAction.self, schema: "public", table: "users" ) @@ -3817,9 +3817,9 @@ functions: name: Listen to inserts using callback code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let subscription = await channel.onPostgresChange( + let subscription = channel.onPostgresChange( InsertAction.self, schema: "public", table: "users" @@ -3830,7 +3830,7 @@ functions: await channel.subscribe() // remove subscription some time later - subscription.remove() + subscription.cancel() ``` - id: listen-to-updates name: Listen to updates @@ -3843,9 +3843,9 @@ functions: ``` code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let updates = await channel.postgresChange( + let updates = channel.postgresChange( UpdateAction.self, schema: "public", table: "users" @@ -3868,9 +3868,9 @@ functions: ``` code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let subscription = await channel.onPostgresChange( + let subscription = channel.onPostgresChange( UpdateAction.self, schema: "public", table: "users" @@ -3881,7 +3881,7 @@ functions: await channel.subscribe() // remove subscription some time later - subscription.remove() + subscription.cancel() ``` - id: listen-to-deletes name: Listen to deletes @@ -3894,9 +3894,9 @@ functions: ``` code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let deletions = await channel.postgresChange( + let deletions = channel.postgresChange( DeleteAction.self, schema: "public", table: "users" @@ -3919,9 +3919,9 @@ functions: ``` code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let subscription = await channel.onPostgresChange( + let subscription = channel.onPostgresChange( DeleteAction.self, schema: "public", table: "users" @@ -3932,15 +3932,15 @@ functions: await channel.subscribe() // remove subscription some time later - subscription.remove() + subscription.cancel() ``` - id: listening-to-row-level-changes name: Listen to row level changes code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let deletions = await channel.postgresChange( + let deletions = channel.postgresChange( DeleteAction.self, schema: "public", table: "users", @@ -3957,9 +3957,9 @@ functions: name: Listen to row level changes using callback code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") - let subscription = await channel.onPostgresChange( + let subscription = channel.onPostgresChange( DeleteAction.self, schema: "public", table: "users", @@ -3971,7 +3971,7 @@ functions: await channel.subscribe() // remove subscription some time later - subscription.remove() + subscription.cancel() ``` - id: remove-channel @@ -3988,7 +3988,7 @@ functions: isSpotlight: true code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") //... await supabase.removeChannel(channel) @@ -3998,7 +3998,7 @@ functions: isSpotlight: true code: | ```swift - let channel = await supabase.channel("channelId") + let channel = supabase.channel("channelId") //... await channel.unsubscribe() @@ -4029,7 +4029,7 @@ functions: isSpotlight: true code: | ```swift - let channels = await supabase.channels + let channels = supabase.channels ``` - id: list-buckets