Skip to content

Commit cc9f480

Browse files
authored
(DOCSP-21678): Add Flex Sync property wrappers to docs and SwiftUI Quick Start (#1949)
* Add Flex Sync property wrappers to docs and SwiftUI Quick Start * Update SPM to use Realm Swift/master and update to new sub write API name * Incorporate feedback * Add links to PBS and FS docs, clarify PBS vs FS * Update SwiftUI docs & quickstart with initialSubscriptions * Fix autoOpen references, generate a snippet without the config comment * Add check for existing subscription, revert to initialSubscriptions, update for SDK release version
1 parent fa8f1ca commit cc9f480

File tree

30 files changed

+1674
-287
lines changed

30 files changed

+1674
-287
lines changed

examples/ios/QuickStartSwiftUI/QuickStart.swift

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let randomNouns = [
3535
"cork", "mouse pad"
3636
]
3737

38-
/// An individual item. Part of a `Group`.
38+
/// An individual item. Part of a `ItemGroup`.
3939
final class Item: Object, ObjectKeyIdentifiable {
4040
/// The unique ID of the Item. `primaryKey: true` declares the
4141
/// _id member as the primary key to the realm.
@@ -47,17 +47,17 @@ final class Item: Object, ObjectKeyIdentifiable {
4747
/// A flag indicating whether the user "favorited" the item.
4848
@Persisted var isFavorite = false
4949

50-
/// The backlink to the `Group` this item is a part of.
51-
@Persisted(originProperty: "items") var group: LinkingObjects<Group>
50+
/// The backlink to the `ItemGroup` this item is a part of.
51+
@Persisted(originProperty: "items") var itemGroup: LinkingObjects<ItemGroup>
5252
}
5353

5454
/// Represents a collection of items.
55-
final class Group: Object, ObjectKeyIdentifiable {
56-
/// The unique ID of the Group. `primaryKey: true` declares the
55+
final class ItemGroup: Object, ObjectKeyIdentifiable {
56+
/// The unique ID of the ItemGroup. `primaryKey: true` declares the
5757
/// _id member as the primary key to the realm.
5858
@Persisted(primaryKey: true) var _id: ObjectId
5959

60-
/// The collection of Items in this group.
60+
/// The collection of Items in this itemGroup.
6161
@Persisted var items = RealmSwift.List<Item>()
6262
}
6363
// :snippet-end:
@@ -94,21 +94,21 @@ struct ContentView: SwiftUI.App {
9494
/// The main content view if not using Sync.
9595
struct LocalOnlyContentView: View {
9696
// :snippet-start: implicitly-open-realm
97-
// Implicitly use the default realm's objects(Group.self)
98-
@ObservedResults(Group.self) var groups
97+
// Implicitly use the default realm's objects(ItemGroup.self)
98+
@ObservedResults(ItemGroup.self) var itemGroups
9999
// :snippet-end:
100100

101101
var body: some View {
102-
if let group = groups.first {
103-
// Pass the Group objects to a view further
102+
if let itemGroup = itemGroups.first {
103+
// Pass the ItemGroup objects to a view further
104104
// down the hierarchy
105-
ItemsView(group: group)
105+
ItemsView(itemGroup: itemGroup)
106106
} else {
107-
// For this small app, we only want one group in the realm.
108-
// You can expand this app to support multiple groups.
109-
// For now, if there is no group, add one here.
107+
// For this small app, we only want one itemGroup in the realm.
108+
// You can expand this app to support multiple itemGroups.
109+
// For now, if there is no itemGroup, add one here.
110110
ProgressView().onAppear {
111-
$groups.append(Group())
111+
$itemGroups.append(ItemGroup())
112112
}
113113
}
114114
}
@@ -164,13 +164,13 @@ struct OpenSyncedRealmView: View {
164164
// The realm has been opened and is ready for use.
165165
// Show the content view.
166166
case .open(let realm):
167-
ItemsView(group: {
168-
if realm.objects(Group.self).count == 0 {
167+
ItemsView(itemGroup: {
168+
if realm.objects(ItemGroup.self).count == 0 {
169169
try! realm.write {
170-
realm.add(Group())
170+
realm.add(ItemGroup())
171171
}
172172
}
173-
return realm.objects(Group.self).first!
173+
return realm.objects(ItemGroup.self).first!
174174
}(), leadingBarButton: AnyView(LogoutButton())).environment(\.realm, realm)
175175
// The realm is currently being downloaded from the server.
176176
// Show a progress view.
@@ -259,12 +259,12 @@ struct LogoutButton: View {
259259

260260
// MARK: Item Views
261261
// :snippet-start: items-view
262-
/// The screen containing a list of items in a group. Implements functionality for adding, rearranging,
263-
/// and deleting items in the group.
262+
/// The screen containing a list of items in a itemGroup. Implements functionality for adding, rearranging,
263+
/// and deleting items in the itemGroup.
264264
struct ItemsView: View {
265-
/// The group is a container for a list of items. Using a group instead of all items
265+
/// The itemGroup is a container for a list of items. Using an itemGroup instead of all items
266266
/// directly allows us to maintain a list order that can be updated in the UI.
267-
@ObservedRealmObject var group: Group
267+
@ObservedRealmObject var itemGroup: ItemGroup
268268

269269
/// The button to be displayed on the top left.
270270
var leadingBarButton: AnyView?
@@ -274,26 +274,25 @@ struct ItemsView: View {
274274
VStack {
275275
// The list shows the items in the realm.
276276
List {
277-
ForEach(group.items) { item in
277+
ForEach(itemGroup.items) { item in
278278
ItemRow(item: item)
279-
}.onDelete(perform: $group.items.remove)
280-
.onMove(perform: $group.items.move)
279+
}.onDelete(perform: $itemGroup.items.remove)
280+
.onMove(perform: $itemGroup.items.move)
281281
}.listStyle(GroupedListStyle())
282282
.navigationBarTitle("Items", displayMode: .large)
283283
.navigationBarBackButtonHidden(true)
284284
.navigationBarItems(
285285
leading: self.leadingBarButton,
286286
// Edit button on the right to enable rearranging items
287287
trailing: EditButton())
288-
289288
// Action bar at bottom contains Add button.
290289
HStack {
291290
Spacer()
292291
Button(action: {
293292
// The bound collection automatically
294293
// handles write transactions, so we can
295294
// append directly to it.
296-
$group.items.append(Item())
295+
$itemGroup.items.append(Item())
297296
}) { Image(systemName: "plus") }
298297
}.padding()
299298
}

0 commit comments

Comments
 (0)