@@ -35,7 +35,7 @@ let randomNouns = [
35
35
" cork " , " mouse pad "
36
36
]
37
37
38
- /// An individual item. Part of a `Group `.
38
+ /// An individual item. Part of a `ItemGroup `.
39
39
final class Item : Object , ObjectKeyIdentifiable {
40
40
/// The unique ID of the Item. `primaryKey: true` declares the
41
41
/// _id member as the primary key to the realm.
@@ -47,17 +47,17 @@ final class Item: Object, ObjectKeyIdentifiable {
47
47
/// A flag indicating whether the user "favorited" the item.
48
48
@Persisted var isFavorite = false
49
49
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 >
52
52
}
53
53
54
54
/// 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
57
57
/// _id member as the primary key to the realm.
58
58
@Persisted ( primaryKey: true ) var _id : ObjectId
59
59
60
- /// The collection of Items in this group .
60
+ /// The collection of Items in this itemGroup .
61
61
@Persisted var items = RealmSwift . List < Item > ( )
62
62
}
63
63
// :snippet-end:
@@ -94,21 +94,21 @@ struct ContentView: SwiftUI.App {
94
94
/// The main content view if not using Sync.
95
95
struct LocalOnlyContentView : View {
96
96
// :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
99
99
// :snippet-end:
100
100
101
101
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
104
104
// down the hierarchy
105
- ItemsView ( group : group )
105
+ ItemsView ( itemGroup : itemGroup )
106
106
} 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.
110
110
ProgressView ( ) . onAppear {
111
- $groups . append ( Group ( ) )
111
+ $itemGroups . append ( ItemGroup ( ) )
112
112
}
113
113
}
114
114
}
@@ -164,13 +164,13 @@ struct OpenSyncedRealmView: View {
164
164
// The realm has been opened and is ready for use.
165
165
// Show the content view.
166
166
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 {
169
169
try ! realm. write {
170
- realm. add ( Group ( ) )
170
+ realm. add ( ItemGroup ( ) )
171
171
}
172
172
}
173
- return realm. objects ( Group . self) . first!
173
+ return realm. objects ( ItemGroup . self) . first!
174
174
} ( ) , leadingBarButton: AnyView ( LogoutButton ( ) ) ) . environment ( \. realm, realm)
175
175
// The realm is currently being downloaded from the server.
176
176
// Show a progress view.
@@ -259,12 +259,12 @@ struct LogoutButton: View {
259
259
260
260
// MARK: Item Views
261
261
// :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 .
264
264
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
266
266
/// 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
268
268
269
269
/// The button to be displayed on the top left.
270
270
var leadingBarButton : AnyView ?
@@ -274,26 +274,25 @@ struct ItemsView: View {
274
274
VStack {
275
275
// The list shows the items in the realm.
276
276
List {
277
- ForEach ( group . items) { item in
277
+ ForEach ( itemGroup . items) { item in
278
278
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)
281
281
} . listStyle ( GroupedListStyle ( ) )
282
282
. navigationBarTitle ( " Items " , displayMode: . large)
283
283
. navigationBarBackButtonHidden ( true )
284
284
. navigationBarItems (
285
285
leading: self . leadingBarButton,
286
286
// Edit button on the right to enable rearranging items
287
287
trailing: EditButton ( ) )
288
-
289
288
// Action bar at bottom contains Add button.
290
289
HStack {
291
290
Spacer ( )
292
291
Button ( action: {
293
292
// The bound collection automatically
294
293
// handles write transactions, so we can
295
294
// append directly to it.
296
- $group . items. append ( Item ( ) )
295
+ $itemGroup . items. append ( Item ( ) )
297
296
} ) { Image ( systemName: " plus " ) }
298
297
} . padding ( )
299
298
}
0 commit comments