-
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathllms.txt
More file actions
1005 lines (790 loc) · 36.5 KB
/
Copy pathllms.txt
File metadata and controls
1005 lines (790 loc) · 36.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
TITLE: Creating and Using a Boutique Store in Swift
DESCRIPTION: Demonstrates how to create a Store object and use its core methods (insert, remove, removeAll) to manage persisted data. The Store handles data persistence automatically and ensures uniqueness of items based on an identifier.
SOURCE: https://github.com/mergesort/Boutique/blob/main/README.md#2025-04-11_snippet_0
LANGUAGE: Swift
CODE:
// Create a Store ¹
let store = Store<Animal>(
storage: SQLiteStorageEngine.default(appendingPath: "Animals"),
cacheIdentifier: \.id
)
// Insert an item into the Store ²
let redPanda = Animal(id: "red_panda")
try await store.insert(redPanda)
// Remove an animal from the Store
try await store.remove(redPanda)
// Insert two more animals to the Store
let dog = Animal(id: "dog")
let cat = Animal(id: "cat")
try await store.insert([dog, cat])
// You can read items directly
print(store.items) // Prints [dog, cat]
// You also don't have to worry about maintaining uniqueness, the Store handles uniqueness for you
let secondDog = Animal(id: "dog")
try await store.insert(secondDog)
print(store.items) // Prints [dog, cat]
// Clear your store by removing all the items at once.
store.removeAll()
print(store.items) // Prints []
// You can even chain commands together
try await store
.insert(dog)
.insert(cat)
.run()
print(store.items) // Prints [dog, cat]
// This is a good way to clear stale cached data
try await store
.removeAll()
.insert(redPanda)
.run()
print(store.items) // Prints [redPanda]
----------------------------------------
TITLE: Creating and Using a Boutique Store in Swift
DESCRIPTION: This snippet demonstrates how to create a Store, insert and remove items, read directly from the store, and chain commands. The Store handles uniqueness automatically and provides real-time updates through @Published properties.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_0
LANGUAGE: swift
CODE:
// Create a Store ¹
let store = Store<Animal>(
storage: SQLiteStorageEngine.default(appendingPath: "Animals"),
cacheIdentifier: \.id
)
// Insert an item into the Store ²
let redPanda = Animal(id: "red_panda")
try await store.insert(redPanda)
// Remove an animal from the Store
try await store.remove(redPanda)
// Insert two more animals to the Store
let dog = Animal(id: "dog")
let cat = Animal(id: "cat")
try await store.insert([dog, cat])
// You can read items directly
print(store.items) // Prints [dog, cat]
// You also don't have to worry about maintaining uniqueness, the Store handles uniqueness for you
let secondDog = Animal(id: "dog")
try await store.insert(secondDog)
print(store.items) // Prints [dog, cat]
// Clear your store by removing all the items at once.
store.removeAll()
print(store.items) // Prints []
// You can even chain commands together
try await store
.insert(dog)
.insert(cat)
.run()
print(store.items) // Prints [dog, cat]
// This is a good way to clear stale cached data
try await store
.removeAll()
.insert(redPanda)
.run()
print(store.items) // Prints [redPanda]
----------------------------------------
TITLE: Initializing Store in Swift for Boutique Library
DESCRIPTION: Demonstrates the usage of Store in Boutique for persisting data automatically and exposing it as a Swift array. This snippet shows how to use the Store concept, which is central to Boutique's functionality.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_1
LANGUAGE: swift
CODE:
Store
----------------------------------------
TITLE: Implementing Note Storage and Management with @Stored in Swift
DESCRIPTION: Demonstrates how to use the @Stored property wrapper to cache notes in memory and on disk. Shows initialization of a Store, fetching notes from an API, and performing CRUD operations on the stored notes.
SOURCE: https://github.com/mergesort/Boutique/blob/main/README.md#2025-04-11_snippet_3
LANGUAGE: swift
CODE:
extension Store where Item == Note {
// Initialize a Store to save our notes into
static let notesStore = Store<Note>(
storage: SQLiteStorageEngine.default(appendingPath: "Notes")
)
}
@Observable
final class NotesController {
/// Creates an @Stored property to handle an in-memory and on-disk cache of notes. ³
@Stored(in: .notesStore) var notes
/// Fetches `Notes` from the API, providing the user with a red panda note if the request succeeds.
func fetchNotes() async throws -> Note {
// Hit the API that provides you a random image's metadata
let noteURL = URL(string: "https://notes.redpanda.club/random/json")!
let randomNoteRequest = URLRequest(url: noteURL)
let (noteResponse, _) = try await URLSession.shared.data(for: randomNoteRequest)
return Note(createdAt: .now, url: noteResponse.url, text: noteResponse.text)
}
/// Saves an note to the `Store` in memory and on disk.
func saveNote(note: Note) async throws {
try await self.$notes.insert(note)
}
/// Removes one note from the `Store` in memory and on disk.
func removeNote(note: Note) async throws {
try await self.$notes.remove(note)
}
/// Removes all of the notes from the `Store` in memory and on disk.
func clearAllNotes() async throws {
try await self.$notes.removeAll()
}
}
----------------------------------------
TITLE: Implementing Data Controller with @Stored Property Wrapper in Swift
DESCRIPTION: Example of a NotesController class using @Stored property wrapper to manage an array of Notes with CRUD operations and API synchronization.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/The @Stored Family Of Property Wrappers.md#2025-04-11_snippet_0
LANGUAGE: swift
CODE:
@Observable
final class NotesController {
@ObservationIgnored
@Stored var notes: [Note]
init(store: Store<Note>) {
self._notes = Stored(in: store)
}
func fetchNotesFromAPI() async throws -> [Note] {
// This would be an API call we make to our server
try await self.fetchAllNotesFromServer()
// Insert all of the notes we fetched into the local Store once the request succeeds, to keep the state in sync
try await self.$notes.insert(notes)
}
func addNote(note: Note) async throws {
// This would be an API call we make to our server
try await self.insertNoteOnServer(note)
// Insert our note into the local Store once the request succeeds, to keep the state in sync
try await self.$notes.insert(note)
}
func removeNote(note: Note) async throws {
// This would be an API call we make to our server
try await self.removeRemoteNoteFromServer(note)
// Remove our note from the local Store once the request succeeds, to keep the state in sync
try await self.$notes.remove(note)
}
func clearAllNotes() async throws {
// This would be an API call we make to our server
try await self.removeAllNotesOnServer()
// Remove all notes from the local Store once the request succeeds, to keep the state in sync
try await self.$notes.removeAll()
}
}
----------------------------------------
TITLE: Integrating Boutique Store with SwiftUI for Reactive Updates
DESCRIPTION: This snippet shows how to use Boutique's @Published property with SwiftUI for reactive updates. It demonstrates using sink for subscribing to changes and onReceive for updating UI when the store changes.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_2
LANGUAGE: swift
CODE:
// Since items is a @Published property
// you can subscribe to any changes in realtime.
store.$items.sink({ items in
print("Items was updated", items)
})
// Works great with SwiftUI out the box for more complex pipelines.
.onReceive(store.$items, perform: {
self.allItems = $0.filter({ $0.id > 100 })
})
----------------------------------------
TITLE: Implementing @Stored Property Wrapper for Cache Management in Swift
DESCRIPTION: This snippet shows how to use the @Stored property wrapper to create an in-memory and on-disk cache with minimal code. It includes creating a static store extension and implementing methods to fetch, save, and remove images.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_3
LANGUAGE: swift
CODE:
extension Store where Item == RemoteImage {
// Initialize a Store to save our images into
static let imagesStore = Store<RemoteImage>(
storage: SQLiteStorageEngine.default(appendingPath: "Images")
)
}
final class ImagesController: ObservableObject {
/// Creates a @Stored property to handle an in-memory and on-disk cache of images. ⁴
@Stored(in: .imagesStore) var images
/// Fetches `RemoteImage` from the API, providing the user with a red panda if the request succeeds.
func fetchImage() async throws -> RemoteImage {
// Hit the API that provides you a random image's metadata
let imageURL = URL(string: "https://image.redpanda.club/random/json")!
let randomImageRequest = URLRequest(url: imageURL)
let (imageResponse, _) = try await URLSession.shared.data(for: randomImageRequest)
return RemoteImage(createdAt: .now, url: imageResponse.url, width: imageResponse.width, height: imageResponse.height, imageData: imageResponse.imageData)
}
/// Saves an image to the `Store` in memory and on disk.
func saveImage(image: RemoteImage) async throws {
try await self.$images.insert(image)
}
/// Removes one image from the `Store` in memory and on disk.
func removeImage(image: RemoteImage) async throws {
try await self.$images.remove(image)
}
/// Removes all of the images from the `Store` in memory and on disk.
func clearAllImages() async throws {
try await self.$images.removeAll()
}
}
----------------------------------------
TITLE: Using @StoredValue for Persistent Storage in Swift
DESCRIPTION: Demonstrates the usage of @StoredValue property wrapper for storing individual values in UserDefaults. Shows examples of storing various types including booleans, dates, enums, and complex objects.
SOURCE: https://github.com/mergesort/Boutique/blob/main/README.md#2025-04-11_snippet_5
LANGUAGE: swift
CODE:
// Setup a `@StoredValue has the same API.
@StoredValue(key: "hasHapticsEnabled")
var hasHapticsEnabled = false
// You can also store nil values
@StoredValue(key: "lastOpenedDate")
var lastOpenedDate: Date? = nil
// Enums work as well, as long as it conforms to `Codable` and `Equatable`.
@StoredValue(key: "currentTheme")
var currentlySelectedTheme = .light
// Complex objects work as well
struct UserPreferences: Codable, Equatable {
var hasHapticsEnabled: Bool
var prefersDarkMode: Bool
var prefersWideScreen: Bool
var spatialAudioEnabled: Bool
}
@StoredValue(key: "userPreferences")
var preferences = UserPreferences()
// Set the lastOpenedDate to now
$lastOpenedDate.set(.now)
// currentlySelected is now .dark
$currentlySelectedTheme.set(.dark)
// StoredValues that are backed by a boolean also have a toggle() function
$hasHapticsEnabled.toggle()
----------------------------------------
TITLE: Using StoredValue and SecurelyStoredValue Property Wrappers in Swift
DESCRIPTION: Demonstrates how to use @StoredValue to persist various types of data in UserDefaults with a publisher for change notifications. Shows storing booleans, optional values, enums, and complex objects, along with methods to modify the stored values.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_4
LANGUAGE: swift
CODE:
// Setup a `@StoredValue has the same API.
@StoredValue(key: "hasHapticsEnabled")
var hasHapticsEnabled = false
// You can also store nil values
@StoredValue(key: "lastOpenedDate")
var lastOpenedDate: Date? = nil
// Enums work as well, as long as it conforms to `Codable` and `Equatable`.
@StoredValue(key: "currentTheme")
var currentlySelectedTheme = .light
// Complex objects work as well
struct UserPreferences: Codable, Equatable {
var hasHapticsEnabled: Bool
var prefersDarkMode: Bool
var prefersWideScreen: Bool
var spatialAudioEnabled: Bool
}
@StoredValue(key: "userPreferences")
var preferences = UserPreferences()
// Set the lastOpenedDate to now
$lastOpenedDate.set(.now)
// currentlySelected is now .dark
$currentlySelectedTheme.set(.dark)
// StoredValues that are backed by a boolean also have a toggle() function
$hasHapticsEnabled.toggle()
----------------------------------------
TITLE: Implementing Notes Controller with @Stored Property Wrapper in Swift
DESCRIPTION: Example implementation of a NotesController class using @Stored property wrapper to manage a collection of notes with persistence and API synchronization.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_5
LANGUAGE: swift
CODE:
@Observable
final class NotesController {
@ObservationIgnored
@Stored var notes: [Note]
init(store: Store<Note>) {
self._notes = Stored(in: store)
}
func fetchNotesFromAPI() async throws -> [Note] {
// This would be an API call we make to our server
try await self.fetchAllNotesFromServer()
// Insert all of the notes we fetched into the local Store once the request succeeds, to keep the state in sync
try await self.$notes.insert(notes)
}
func addNote(note: Note) async throws {
// This would be an API call we make to our server
try await self.insertNoteOnServer(note)
// Insert our note into the local Store once the request succeeds, to keep the state in sync
try await self.$notes.insert(note)
}
func removeNote(note: Note) async throws {
// This would be an API call we make to our server
try await self.removeRemoteNoteFromServer(note)
// Remove our note from the local Store once the request succeeds, to keep the state in sync
try await self.$notes.remove(note)
}
func clearAllNotes() async throws {
// This would be an API call we make to our server
try await self.removeAllNotesOnServer()
// Remove all notes from the local Store once the request succeeds, to keep the state in sync
try await self.$notes.removeAll()
}
}
----------------------------------------
TITLE: Initializing @StoredValue in an Observable Class
DESCRIPTION: Example of setting up @StoredValue property wrappers in an @Observable class to persist user preferences. This requires the @ObservationIgnored attribute to properly work with the observation system.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/The @Stored Family Of Property Wrappers.md#2025-04-11_snippet_4
LANGUAGE: swift
CODE:
@Observable
final class Preferences {
@ObservationIgnored
@StoredValue(key: "hasHapticsEnabled")
var hasHapticsEnabled = false
@ObservationIgnored
@StoredValue(key: "lastOpenedDate")
var lastOpenedDate: Date? = nil
@ObservationIgnored
@StoredValue(key: "currentTheme")
var currentlySelectedTheme = .light
}
----------------------------------------
TITLE: Observing Store Changes with SwiftUI's onChange Modifier
DESCRIPTION: Shows how to subscribe to changes in a Boutique Store using SwiftUI's onChange modifier. This enables reactive UI updates when store data changes.
SOURCE: https://github.com/mergesort/Boutique/blob/main/README.md#2025-04-11_snippet_1
LANGUAGE: Swift
CODE:
// Since @Store, @StoredValue, and @SecurelyStoredValue are `@Observable`, you can subscribe
// to changes in realtime using any of Swift's built-in observability mechanisms.
.onChange(of: store.items) {
self.items = self.items.sorted(by: { $0.createdAt > $1.createdAt})
})
----------------------------------------
TITLE: Implementing SwiftUI View with Store Observation
DESCRIPTION: Example of a SwiftUI view that observes changes to a Store using onChange modifier and handles user interactions. This pattern helps keep the UI in sync with the data store.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_17
LANGUAGE: swift
CODE:
struct NotesListView: View {
@State var notesController: NotesController
@State private var notes: [Note] = []
var body: some View {
VStack {
ForEach(self.notes) { note in
Text(note.text)
.onTapGesture {
Task {
try await notesController.removeNote(note)
}
}
}
}
.onChange(of: notesController.notes, initial: true) { _, newValue in
// We can even create complex pipelines, for example filtering all notes smaller than a tweet
self.notes = newValue.filter { $0.length < 280 }
}
}
}
----------------------------------------
TITLE: Observing Store Changes with SwiftUI's onChange Modifier in Boutique
DESCRIPTION: Demonstrates how to observe changes to a Store's items using SwiftUI's .onChange modifier. The example shows a NotesListView that displays filtered notes and updates the view whenever the notes collection changes. The 'initial: true' parameter ensures the handler is called when the view first appears.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/Using Stores.md#2025-04-11_snippet_9
LANGUAGE: swift
CODE:
struct NotesListView: View {
@State var notesController: NotesController
@State private var notes: [Note] = []
var body: some View {
VStack {
ForEach(self.notes) { note in
Text(note.text)
.onTapGesture {
Task {
try await notesController.removeNote(note)
}
}
}
}
.onChange(of: notesController.notes, initial: true) { _, newValue in
// We can even create complex pipelines, for example filtering all notes smaller than a tweet
self.notes = newValue.filter { $0.length < 280 }
}
}
}
----------------------------------------
TITLE: Observing Store Changes in SwiftUI with onChange Modifier
DESCRIPTION: Shows how to observe changes to a Store's items using SwiftUI's .onChange modifier. This example demonstrates filtering the results to only include notes shorter than 280 characters.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_11
LANGUAGE: swift
CODE:
struct NotesListView: View {
@State var notesController: NotesController
@State private var notes: [Note] = []
var body: some View {
VStack {
ForEach(self.notes) { note in
Text(note.text)
.onTapGesture {
Task {
try await notesController.removeNote(note)
}
}
}
}
.onChange(of: notesController.notes, initial: true) { _, newValue in
// We can even create complex pipelines, for example filtering all notes smaller than a tweet
self.notes = newValue.filter { $0.length < 280 }
}
}
}
----------------------------------------
TITLE: Chaining Store Operations in Swift
DESCRIPTION: Demonstrates how to chain multiple Store operations using the run() function. This approach allows for executing multiple operations in a single transaction.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_16
LANGUAGE: swift
CODE:
try await store
.removeAll()
.insert(coat)
.run()
----------------------------------------
TITLE: Using Boutique's Granular Events Tracking API
DESCRIPTION: Demonstrates how to monitor specific events in a Boutique Store using the Granular Events Tracking API. This allows for detailed tracking of store operations like initialization, loading, insertion, and removal.
SOURCE: https://github.com/mergesort/Boutique/blob/main/README.md#2025-04-11_snippet_2
LANGUAGE: Swift
CODE:
// You can also use Boutique's Granular Events Tracking API to be notified of individual changes.
func monitorNotesStoreEvents() async {
for await event in self.notesController.$notes.events {
switch event.operation {
case .initialized:
print("[Store Event: initial] Our Notes Store has initialized")
case .loaded:
print("[Store Event: loaded] Our Notes Store has loaded with notes", event.notes.map(\.text))
case .insert:
print("[Store Event: insert] Our Notes Store inserted notes", event.notes.map(\.text))
case .remove:
print("[Store Event: remove] Our Notes Store removed notes", event.notes.map(\.text))
}
}
}
----------------------------------------
TITLE: Using StoredValue Property Wrapper in Swift
DESCRIPTION: Illustrates the use of the @StoredValue property wrapper in Boutique for persisting individual Swift values. This property wrapper simplifies saving single values using Boutique's storage mechanism.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_30
LANGUAGE: swift
CODE:
@StoredValue
----------------------------------------
TITLE: Monitoring Granular Events in Boutique Store for Swift
DESCRIPTION: This code snippet demonstrates how to use the Granular Events API in Boutique to monitor detailed events in a Notes Store. It showcases handling different operations like initialization, loading, insertion, and removal of notes.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_7
LANGUAGE: swift
CODE:
func monitorNotesEvents() async {
for await event in notesController.$notes.events {
switch event.operation {
case .initialized:
print("Notes Store has initialized")
case .loaded:
print("Notes Store has loaded with notes", event.items)
case .insert:
print("Notes Store inserted notes", event.items)
case .remove:
print("Notes Store removed notes", event.items)
}
}
}
----------------------------------------
TITLE: Monitoring Granular Store Events in Boutique
DESCRIPTION: Shows how to use the Granular Events API to observe specific operations on a Store. This approach provides detailed information about what type of event occurred (initialization, loading, insertion, removal) and which specific items were affected by the change.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/Using Stores.md#2025-04-11_snippet_10
LANGUAGE: swift
CODE:
func monitorNotesEvents() async {
for await event in notesController.$notes.events {
switch event.operation {
case .initialized:
print("Notes Store has initialized")
case .loaded:
print("Notes Store has loaded with notes", event.items)
case .insert:
print("Notes Store inserted notes", event.items)
case .remove:
print("Notes Store removed notes", event.items)
}
}
}
----------------------------------------
TITLE: Using SecurelyStoredValue Property Wrapper in Swift with Boutique
DESCRIPTION: Shows the usage of the @SecurelyStoredValue property wrapper for securely persisting individual Swift values with added security measures.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_31
LANGUAGE: swift
CODE:
@SecurelyStoredValue
----------------------------------------
TITLE: Granular Store Event Monitoring
DESCRIPTION: Example of monitoring granular Store events using AsyncStream to track different operations like initialization, loading, insertion, and removal.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/The @Stored Family Of Property Wrappers.md#2025-04-11_snippet_3
LANGUAGE: swift
CODE:
func monitorNotesEvents() async {
for await event in notesController.$notes.events {
switch event.operation {
case .initialized:
print("Notes Store has initialized")
case .loaded:
print("Notes Store has loaded with notes", event.items)
case .insert:
print("Notes Store inserted notes", event.items)
case .remove:
print("Notes Store removed notes", event.items)
}
}
}
----------------------------------------
TITLE: Initializing Store with SQLiteStorageEngine
DESCRIPTION: Creates a Store instance with SQLite persistence using a custom cache identifier. The store is configured with a storage directory and unique identifier path.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/Using Stores.md#2025-04-11_snippet_0
LANGUAGE: swift
CODE:
let store = Store<Item>(
storage: SQLiteStorageEngine(directory: .defaultStorageDirectory(appendingPath: "Items")),
cacheIdentifier: \.id
)
----------------------------------------
TITLE: Monitoring Granular Store Events with AsyncStream in Swift
DESCRIPTION: Example showing how to monitor granular events from a Store using AsyncStream<StoreEvent>. This allows tracking specific operations like initialization, loading, insertion, and removal of items.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_18
LANGUAGE: swift
CODE:
func monitorNotesEvents() async {
for await event in notesController.$notes.events {
switch event.operation {
case .initialized:
print("Notes Store has initialized")
case .loaded:
print("Notes Store has loaded with notes", event.items)
case .insert:
print("Notes Store inserted notes", event.items)
case .remove:
print("Notes Store removed notes", event.items)
}
}
}
----------------------------------------
TITLE: Asynchronous Store Initialization
DESCRIPTION: Example of initializing a Store asynchronously to ensure items are loaded before access.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/Using Stores.md#2025-04-11_snippet_7
LANGUAGE: swift
CODE:
let store: Store<Item>
init() async throws {
store = try await Store(...)
// Now the store will have `items` already loaded.
let items = await store.items
}
----------------------------------------
TITLE: Waiting for Store Items to Load in Swift
DESCRIPTION: Demonstrates how to wait for items to load after synchronous Store initialization. The itemsHaveLoaded() method ensures all items are loaded before they are accessed.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_15
LANGUAGE: swift
CODE:
let store: Store<Item> = Store(...)
func getItems() async -> [Item] {
try await store.itemsHaveLoaded()
return await store.items
}
----------------------------------------
TITLE: Synchronous Store Initialization with Async Loading
DESCRIPTION: Shows how to initialize a Store synchronously while waiting for items to load before access.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/Using Stores.md#2025-04-11_snippet_8
LANGUAGE: swift
CODE:
let store: Store<Item> = Store(...)
func getItems() async -> [Item] {
try await store.itemsHaveLoaded()
return await store.items
}
----------------------------------------
TITLE: Inserting an Item into a Store in Swift
DESCRIPTION: Shows how to insert an item into a Store using the insert method. This asynchronous operation adds a new item to the persistent storage.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_23
LANGUAGE: swift
CODE:
let coat = Item(name: "coat")
try await store.insert(coat)
----------------------------------------
TITLE: Observing @StoredValue Changes with AsyncStream
DESCRIPTION: Shows how to monitor changes to a @StoredValue using the values property, which returns an AsyncStream. This allows for reactive programming with stored values using Swift's structured concurrency.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/The @Stored Family Of Property Wrappers.md#2025-04-11_snippet_10
LANGUAGE: swift
CODE:
func monitorThemeChanges() async {
for await theme in preferences.$currentlySelectedTheme.values {
print("Theme changed to", theme)
}
}
----------------------------------------
TITLE: Storing Complex Types with @StoredValue
DESCRIPTION: Example of storing a custom Codable struct using @StoredValue. This demonstrates how Boutique can persist more complex data structures beyond simple value types.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/The @Stored Family Of Property Wrappers.md#2025-04-11_snippet_6
LANGUAGE: swift
CODE:
struct UserPreferences: Codable, Sendable, Equatable {
var hasHapticsEnabled: Bool
var prefersDarkMode: Bool
var prefersWideScreen: Bool
var spatialAudioEnabled: Bool
}
@Observable
final class PreferencesManager {
@ObservationIgnored
@StoredValue(key: "userPreferences")
var preferences = UserPreferences()
}
----------------------------------------
TITLE: Removing an Item from a Store in Swift
DESCRIPTION: Demonstrates how to remove a specific item from a Store. This asynchronous operation deletes the item from the persistent storage.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_24
LANGUAGE: swift
CODE:
try await store.remove(coat)
----------------------------------------
TITLE: Injecting Store into NotesController with @Stored in Swift
DESCRIPTION: Shows how to decouple the store from the view model, controller, or manager object by injecting stores into the object using @Stored property wrapper.
SOURCE: https://github.com/mergesort/Boutique/blob/main/README.md#2025-04-11_snippet_4
LANGUAGE: swift
CODE:
@Observable
final class NotesController {
@ObservationIgnored
@Stored var notes: [Note]
init(store: Store<Note>) {
self._notes = Stored(in: store)
}
}
----------------------------------------
TITLE: Chaining Store Operations
DESCRIPTION: Shows how to chain multiple Store operations using the run() function for atomic execution.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/Using Stores.md#2025-04-11_snippet_6
LANGUAGE: swift
CODE:
try await store
.removeAll()
.insert(coat)
.run()
----------------------------------------
TITLE: Injecting Boutique Store into Controller for Dependency Injection
DESCRIPTION: This snippet demonstrates how to decouple a store from the controller by injecting it via initialization. This approach enables better testability and dependency management.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_8
LANGUAGE: swift
CODE:
final class ImagesController: ObservableObject {
@Stored var images: [RemoteImage]
init(store: Store<RemoteImage>) {
self._images = Stored(in: store)
}
}
----------------------------------------
TITLE: Asynchronous Store Initialization in Swift
DESCRIPTION: Shows how to initialize a Store asynchronously to ensure items are loaded before access. This approach guarantees that the items are available when the store is first accessed.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_14
LANGUAGE: swift
CODE:
let store: Store<Item>
init() async throws {
store = try await Store(...)
// Now the store will have `items` already loaded.
let items = await store.items
}
----------------------------------------
TITLE: Observing @SecurelyStoredValue Changes
DESCRIPTION: Shows how to monitor changes to a @SecurelyStoredValue using the values property. This works similar to @StoredValue observation but with securely stored keychain values.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/The @Stored Family Of Property Wrappers.md#2025-04-11_snippet_13
LANGUAGE: swift
CODE:
func monitorPasswordChanges() async {
for await password in securityManager.$storedPassword.values {
if let password {
print("Password was set")
} else {
print("Password was removed")
}
}
}
----------------------------------------
TITLE: Observing StoredValue Changes Asynchronously in Swift
DESCRIPTION: This example shows how to observe changes to a StoredValue using the values property in an asynchronous context. The for-await loop processes each change to the theme as it occurs.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_21
LANGUAGE: swift
CODE:
func monitorThemeChanges() async {
for await theme in preferences.$currentlySelectedTheme.values {
print("Theme changed to", theme)
}
}
----------------------------------------
TITLE: Initializing @SecurelyStoredValue for Keychain Storage
DESCRIPTION: Example of setting up the @SecurelyStoredValue property wrapper to store sensitive data in the system Keychain. This requires the @ObservationIgnored attribute in @Observable classes.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/The @Stored Family Of Property Wrappers.md#2025-04-11_snippet_11
LANGUAGE: swift
CODE:
@Observable
final class SecurityManager {
@ObservationIgnored
@SecurelyStoredValue<RedPanda>(key: "redPanda")
private var redPanda
}
----------------------------------------
TITLE: Observing SecurelyStoredValue Changes Asynchronously in Swift
DESCRIPTION: This snippet demonstrates how to observe changes to a SecurelyStoredValue using the values property in an asynchronous context. It handles both when a password is set and when it's removed.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_22
LANGUAGE: swift
CODE:
func monitorPasswordChanges() async {
for await password in securityManager.$storedPassword.values {
if let password {
print("Password was set")
} else {
print("Password was removed")
}
}
}
----------------------------------------
TITLE: Initializing SecurelyStoredValue in Swift
DESCRIPTION: This snippet demonstrates how to create a SecurelyStoredValue property in an @Observable class for storing sensitive data in the system Keychain. SecurelyStoredValue provides enhanced security for sensitive information.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_28
LANGUAGE: swift
CODE:
@Observable
final class SecurityManager {
@ObservationIgnored
@SecurelyStoredValue<RedPanda>(key: "redPanda")
private var redPanda
}
----------------------------------------
TITLE: Simplified Store Initialization for Identifiable Items in Swift
DESCRIPTION: Shows a simplified Store initialization when the model conforms to Identifiable. This allows omitting the cacheIdentifier parameter as it uses the id property from Identifiable.
SOURCE: https://github.com/mergesort/Boutique/blob/main/llms.txt#2025-04-11_snippet_19
LANGUAGE: swift
CODE:
let store = Store<Item>(
storage: SQLiteStorageEngine(directory: .defaultStorageDirectory(appendingPath: "Items"))
)
----------------------------------------
TITLE: Organizing Multiple @StoredValue Properties with Observable Classes
DESCRIPTION: Demonstrates how to organize large applications by breaking down objects with many @StoredValue properties into smaller, more focused observable classes while maintaining reactivity.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/The @Stored Family Of Property Wrappers.md#2025-04-11_snippet_14
LANGUAGE: swift
CODE:
@Observable
final class Preferences {
var userExperiencePreferences = UserExperiencePreferences()
var redPandaPreferences = RedPandaPreferences()
}
@MainActor
@Observable
final class UserExperiencePreferences {
@ObservationIgnored
@StoredValue(key: "hasSoundEffectsEnabled")
public var hasSoundEffectsEnabled = false
@ObservationIgnored
@StoredValue(key: "hasHapticsEnabled")
public var hasHapticsEnabled = true
}
@MainActor
@Observable
final class RedPandaPreferences {
@ObservationIgnored
@StoredValue(key: "isRedPandaFan")
public var isRedPandaFan = true
}
----------------------------------------
TITLE: Inserting Items into Store
DESCRIPTION: Demonstrates how to insert a new item into the Store asynchronously.
SOURCE: https://github.com/mergesort/Boutique/blob/main/Sources/Boutique/Documentation.docc/Articles/Using Stores.md#2025-04-11_snippet_3