Post

Replies

Boosts

Views

Activity

How to fix the issue in the code shown at 21:40
At 21:40 in the video the following code is shown: (sorry for the screenshot but this talk doesn't have code copy enabled) Luca points out this results in new view and storage every time dayTime changes. Say you wanted to fix it so it doesn't create a new view and storage every time, how would you do that? Like this maybe? var body: some View { let cr = CatRecorder() if dayTime { return cr.nightTimeStyle() } else { return cr } } But this code doesn't look very declarative. I've seen many struggle with applying modifiers conditionally (especially .hidden()) so thought I'd ask.
1
0
1.5k
Jun ’21
How to show SwiftUI PhotosPicker programatically
Hi I would like to show the PhotosPicker programatically the same way we can do with sheet(isPresented: Binding<Bool>) and fullScreenCover(isPresented: Binding<Bool>), i.e. I would like: photosPicker(isPresented: Binding<Bool>, selectedItem: Binding<PhotosPickerItem?>). This would allow me to have multiple buttons that show the picker and would make all my code that shows sheets consistent, thanks for reading.
2
1
2.9k
Jan ’23
When to purge the persistent history?
I enjoyed the video thanks. At 6mins when David said "You don't need to do anything else and your data will be indexed in Spotlight.". What immediately came to mind was what about cleaning up the persistent history? I had a brief look at the docs and noticed that indexDidUpdateNotification includes NSPersistentHistoryTokenKey should we listen for that and then purge the history? And what if we have multiple components requiring use of the persistent history? Is there a recommended strategy for deleting only the history not required by the Spotlight indexer and other components?
2
0
1.4k
Jun ’21
The new modifyRecordsResultBlock behaves differently from modifyRecordsCompletionBlock
Hi I noticed with CKModifyRecordsOperation, modifyRecordsResultBlock works differently from the now deprecated modifyRecordsCompletionBlock. When using a savePolicy of ifServerRecordUnchanged (which is the default), if the record on the server has been changed since it was downloaded, edited and saved again then modifyRecordsResultBlock unexpectedly does not error. But modifyRecordsCompletionBlock does error which is what I would expect. The kind of error in this case looks like this: "Server Record Changed" (14/2004); server message = "client oplock error updating record"; My question is, is this new behavior by design? By the way, I'm having to write my own async/await version of save records using withTaskCancellationHandler and withCheckedThrowingContinuation because the built-in one does not support task cancellation which I require to use with SwiftUI's .task modifier. Finally, modifyRecordsResultBlock and the other 2 new ones are missing its documentation because it hasn't used the correct DocC format, it's using old style comments which are not being picked up. FB10400023
1
1
2.2k
Dec ’22
Does ModelContext fetch() return an auto-updating results array?
I was wondering if ModelContext's fetch() contains an auto-updating results array? I ask because there is no documentation yet and in the WWDC23 lounge it was suggested by Debbie G to use fetch() to overcome the limitations of @Query i.e. no way to use dynamic filtering or sorting. I suppose we would call fetch() from onAppear and onChanged to support dynamic queries that also have auto-updating of results. Personally I don't understand why @Query and the old @FetchRequest were implemented as property wrappers instead of SwiftUI modifiers, e.g. .fetch(predicate:sort:) to match other modifiers like .task(id:). I was hoping for it to behave similar to Date's formatted() that returns a locale-aware string that automatically invalidates SwiftUI Text when the locale changes. Although I'm not exactly sure how it works. If fetch() doesn't auto-update then what would be the point of using it instead of just using NSFetchRequest with dictionary result type to get data into a SwiftUI view struct fast and memory efficient.
1
1
1.2k
Jun ’23
Code missing from WWDC session video 10210
I noticed the code snippets are missing from the wwdc2024 10210 video titled Bring your app’s core features to users with App Intents https://developer.apple.com/videos/play/wwdc2024/10210/ It would be useful if those could be added. I also noticed the transcript is missing from the web version but it is in the Developer app, that is odd.
1
1
868
Jul ’24
Why is PersistentModel a protocol and not a class?
PersistentModel is a protocol but would make more sense as a class that we then subclass. If all of the implementation was in a parent class of our model classes then there wouldn't be all the problems caused by requiring the use of the @Model macro, e.g. default property values not working, unable to subclass, overriding get/set not possible, conflict in property names...
0
0
844
Aug ’23
Duplicate bar buttons appear when .toolbar is applied to a Group View
Is it normal behaviour that when I apply a .toolbar to a Group that I see duplicate buttons equal to the number of Views in the Group? e.g. Group { Text("1") Text("2") Text("3") } .toolbar { Button("Hi") { } } Results in 3 toolbar buttons appearing in the UI, like in this screenshot: If not, then I'll submit feedback about this bug but thought I'd ask first. Xcode Version 16.0 beta 6 (16A5230g) iPhone 15 Pro Simulator
Topic: UI Frameworks SubTopic: SwiftUI
4
0
926
Sep ’24
SwiftUI FocusState is not working in FocusCookbook sample project
I gave the FocusCookbook sample project a try and FocusState is not working correctly on iOS 18. I understand the sample was originally designed for iOS 17 when it was released along side the WWDC 2023 talk The SwiftUI Cookbook for Focus. however I am suprised it no longer works on iOS 18. E.g. when I launch the app on iPhone 16 Pro simulator (Xcode 16.2, iOS 18.2 Simulator) and tap the grocery list nav bar button, the grocery sheet appears however the last entry text field is not focused like .defaultFocus is designed to do. Futhermore, if I tap the add (+) button and a new entry is added, despite the addEmptyItem() func setting the currentItemID which is the @FocusState var the focus does not change to the new text field. Is FocusState broken on iOS 18? Relevant code from GroceryListView.swift import SwiftUI struct GroceryListView: View { @Environment(\.dismiss) private var dismiss @Binding var list: GroceryList @FocusState private var currentItemID: GroceryList.Item.ID? var body: some View { List($list.items) { $item in HStack { Toggle("Obtained", isOn: $item.isObtained) TextField("Item Name", text: $item.name) .onSubmit { addEmptyItem() } .focused($currentItemID, equals: item.id) } } .toolbar { ToolbarItem(placement: .cancellationAction) { doneButton } ToolbarItem(placement: .primaryAction) { newItemButton } } .defaultFocus($currentItemID, list.items.last?.id) } // MARK: New item private func addEmptyItem() { let newItem = list.addItem() currentItemID = newItem.id } private var newItemButton: some View { Button { addEmptyItem() } label: { Label("New Item", systemImage: "plus") } } private var doneButton: some View { Button { dismiss() } label: { Text("Done") } } }
Topic: UI Frameworks SubTopic: SwiftUI
2
0
483
Feb ’25
Mistake about CKReference in Using Core Data With CloudKit (WWDC 2019)
The presenter says "you might be wondering why we don't do this with CKReference instead. And that's because CKReference has some limitations that we don't think work well for Core Data clients. Namely that it's limited to 750 total objects." However, that isn't correct, the 750 limit is only for references that have a delete action: https://developer.apple.com/documentation/cloudkit/ckrecord/reference Important There is a hard limit to the number of references with a CKRecord.ReferenceAction.deleteSelf action that any one record can have. This limit is 750 references, and any attempt to exceed it results in an error from the server. This is why the Notes app has no issue with more than 750 note records with a reference to a folder record. I really wish NSPersistentCloudKitContainer had used CKReference and also that _CKReferenceActionValidate was made public. CKShare has limitations too, yet it used that and there was no custom sharing done like custom references were done.
0
0
877
May ’22
Bug in NavigationCookbook sample: builtInRecipes are missing their IDs
I noticed a problem with the NavigationCookbook sample code. The builtInRecipes array containing Recipe models without IDs which means state restoration fails because the recipes have new unique IDs every time the app is launched (there is a let id = UUID() in Recipe). The problem is in NavigationCookbook/Models/DataModel private let builtInRecipes: [Recipe] = { var recipes = [ "Apple Pie": Recipe( name: "Apple Pie", category: .dessert, ingredients: applePie.ingredients), Should be let builtInRecipes: [Recipe] = { var recipes = [ "Apple Pie": Recipe( id: UUID(uuidString: "E35A5C9C-F1EA-4B3D-9980-E2240B363AC8")!, name: "Apple Pie", category: .dessert, ingredients: Ingredient.fromLines(applePie)), And the same thing for all the other built-in recipes in the array. The builtInRecipes containing ids can be found in the Code tab in the Developer app for this samples WWDC session video: https://developer.apple.com/wwdc22/10054 I also submitted this as feedback FB11744612
0
0
1.3k
Nov ’22
How to fix the issue in the code shown at 21:40
At 21:40 in the video the following code is shown: (sorry for the screenshot but this talk doesn't have code copy enabled) Luca points out this results in new view and storage every time dayTime changes. Say you wanted to fix it so it doesn't create a new view and storage every time, how would you do that? Like this maybe? var body: some View { let cr = CatRecorder() if dayTime { return cr.nightTimeStyle() } else { return cr } } But this code doesn't look very declarative. I've seen many struggle with applying modifiers conditionally (especially .hidden()) so thought I'd ask.
Replies
1
Boosts
0
Views
1.5k
Activity
Jun ’21
More detail on .backgroundTask(.urlSession("isStormy")) shown at 11:50
In the slides at 11:50 the following code snippet is shown: .backgroundTask(.urlSession("isStormy")) { // ... } Please could you explain what should be done in this block? The video just cuts off right after and seems like the explanation is missing. Thanks.
Replies
3
Boosts
4
Views
2.2k
Activity
Jul ’22
Please fix the "remember me" feature
Every day I visit the forums I have to sign in again despite having ticked the "remember me" check box on the login form. Having to sign in again to make the simplest action of upvoting an answer makes me not want to bother. Safari Version 13.1.1 (15609.2.9.1.2) macOS Catalina 10.15.5 (19F101)
Replies
4
Boosts
0
Views
2.2k
Activity
Dec ’21
How to show SwiftUI PhotosPicker programatically
Hi I would like to show the PhotosPicker programatically the same way we can do with sheet(isPresented: Binding<Bool>) and fullScreenCover(isPresented: Binding<Bool>), i.e. I would like: photosPicker(isPresented: Binding<Bool>, selectedItem: Binding<PhotosPickerItem?>). This would allow me to have multiple buttons that show the picker and would make all my code that shows sheets consistent, thanks for reading.
Replies
2
Boosts
1
Views
2.9k
Activity
Jan ’23
When to purge the persistent history?
I enjoyed the video thanks. At 6mins when David said "You don't need to do anything else and your data will be indexed in Spotlight.". What immediately came to mind was what about cleaning up the persistent history? I had a brief look at the docs and noticed that indexDidUpdateNotification includes NSPersistentHistoryTokenKey should we listen for that and then purge the history? And what if we have multiple components requiring use of the persistent history? Is there a recommended strategy for deleting only the history not required by the Spotlight indexer and other components?
Replies
2
Boosts
0
Views
1.4k
Activity
Jun ’21
The new modifyRecordsResultBlock behaves differently from modifyRecordsCompletionBlock
Hi I noticed with CKModifyRecordsOperation, modifyRecordsResultBlock works differently from the now deprecated modifyRecordsCompletionBlock. When using a savePolicy of ifServerRecordUnchanged (which is the default), if the record on the server has been changed since it was downloaded, edited and saved again then modifyRecordsResultBlock unexpectedly does not error. But modifyRecordsCompletionBlock does error which is what I would expect. The kind of error in this case looks like this: "Server Record Changed" (14/2004); server message = "client oplock error updating record"; My question is, is this new behavior by design? By the way, I'm having to write my own async/await version of save records using withTaskCancellationHandler and withCheckedThrowingContinuation because the built-in one does not support task cancellation which I require to use with SwiftUI's .task modifier. Finally, modifyRecordsResultBlock and the other 2 new ones are missing its documentation because it hasn't used the correct DocC format, it's using old style comments which are not being picked up. FB10400023
Replies
1
Boosts
1
Views
2.2k
Activity
Dec ’22
Does ModelContext fetch() return an auto-updating results array?
I was wondering if ModelContext's fetch() contains an auto-updating results array? I ask because there is no documentation yet and in the WWDC23 lounge it was suggested by Debbie G to use fetch() to overcome the limitations of @Query i.e. no way to use dynamic filtering or sorting. I suppose we would call fetch() from onAppear and onChanged to support dynamic queries that also have auto-updating of results. Personally I don't understand why @Query and the old @FetchRequest were implemented as property wrappers instead of SwiftUI modifiers, e.g. .fetch(predicate:sort:) to match other modifiers like .task(id:). I was hoping for it to behave similar to Date's formatted() that returns a locale-aware string that automatically invalidates SwiftUI Text when the locale changes. Although I'm not exactly sure how it works. If fetch() doesn't auto-update then what would be the point of using it instead of just using NSFetchRequest with dictionary result type to get data into a SwiftUI view struct fast and memory efficient.
Replies
1
Boosts
1
Views
1.2k
Activity
Jun ’23
Code missing from WWDC session video 10210
I noticed the code snippets are missing from the wwdc2024 10210 video titled Bring your app’s core features to users with App Intents https://developer.apple.com/videos/play/wwdc2024/10210/ It would be useful if those could be added. I also noticed the transcript is missing from the web version but it is in the Developer app, that is odd.
Replies
1
Boosts
1
Views
868
Activity
Jul ’24
Why is PersistentModel a protocol and not a class?
PersistentModel is a protocol but would make more sense as a class that we then subclass. If all of the implementation was in a parent class of our model classes then there wouldn't be all the problems caused by requiring the use of the @Model macro, e.g. default property values not working, unable to subclass, overriding get/set not possible, conflict in property names...
Replies
0
Boosts
0
Views
844
Activity
Aug ’23
How can we delete posts?
Please delete this one!
Replies
3
Boosts
0
Views
1.1k
Activity
Jul ’24
Duplicate bar buttons appear when .toolbar is applied to a Group View
Is it normal behaviour that when I apply a .toolbar to a Group that I see duplicate buttons equal to the number of Views in the Group? e.g. Group { Text("1") Text("2") Text("3") } .toolbar { Button("Hi") { } } Results in 3 toolbar buttons appearing in the UI, like in this screenshot: If not, then I'll submit feedback about this bug but thought I'd ask first. Xcode Version 16.0 beta 6 (16A5230g) iPhone 15 Pro Simulator
Topic: UI Frameworks SubTopic: SwiftUI
Replies
4
Boosts
0
Views
926
Activity
Sep ’24
SwiftUI FocusState is not working in FocusCookbook sample project
I gave the FocusCookbook sample project a try and FocusState is not working correctly on iOS 18. I understand the sample was originally designed for iOS 17 when it was released along side the WWDC 2023 talk The SwiftUI Cookbook for Focus. however I am suprised it no longer works on iOS 18. E.g. when I launch the app on iPhone 16 Pro simulator (Xcode 16.2, iOS 18.2 Simulator) and tap the grocery list nav bar button, the grocery sheet appears however the last entry text field is not focused like .defaultFocus is designed to do. Futhermore, if I tap the add (+) button and a new entry is added, despite the addEmptyItem() func setting the currentItemID which is the @FocusState var the focus does not change to the new text field. Is FocusState broken on iOS 18? Relevant code from GroceryListView.swift import SwiftUI struct GroceryListView: View { @Environment(\.dismiss) private var dismiss @Binding var list: GroceryList @FocusState private var currentItemID: GroceryList.Item.ID? var body: some View { List($list.items) { $item in HStack { Toggle("Obtained", isOn: $item.isObtained) TextField("Item Name", text: $item.name) .onSubmit { addEmptyItem() } .focused($currentItemID, equals: item.id) } } .toolbar { ToolbarItem(placement: .cancellationAction) { doneButton } ToolbarItem(placement: .primaryAction) { newItemButton } } .defaultFocus($currentItemID, list.items.last?.id) } // MARK: New item private func addEmptyItem() { let newItem = list.addItem() currentItemID = newItem.id } private var newItemButton: some View { Button { addEmptyItem() } label: { Label("New Item", systemImage: "plus") } } private var doneButton: some View { Button { dismiss() } label: { Text("Done") } } }
Topic: UI Frameworks SubTopic: SwiftUI
Replies
2
Boosts
0
Views
483
Activity
Feb ’25
Help with implementing own sync like Notes
Hi Nick, I've implemented by own sync that works the same as Notes but it requires using the private CKReferenceActionValidate. Could you help make that public? Cheers See https://developer.apple.com/forums/thread/652267 and FB6114162 - 4 Jun 2019
Replies
1
Boosts
0
Views
1.2k
Activity
Jun ’21
Mistake about CKReference in Using Core Data With CloudKit (WWDC 2019)
The presenter says "you might be wondering why we don't do this with CKReference instead. And that's because CKReference has some limitations that we don't think work well for Core Data clients. Namely that it's limited to 750 total objects." However, that isn't correct, the 750 limit is only for references that have a delete action: https://developer.apple.com/documentation/cloudkit/ckrecord/reference Important There is a hard limit to the number of references with a CKRecord.ReferenceAction.deleteSelf action that any one record can have. This limit is 750 references, and any attempt to exceed it results in an error from the server. This is why the Notes app has no issue with more than 750 note records with a reference to a folder record. I really wish NSPersistentCloudKitContainer had used CKReference and also that _CKReferenceActionValidate was made public. CKShare has limitations too, yet it used that and there was no custom sharing done like custom references were done.
Replies
0
Boosts
0
Views
877
Activity
May ’22
Bug in NavigationCookbook sample: builtInRecipes are missing their IDs
I noticed a problem with the NavigationCookbook sample code. The builtInRecipes array containing Recipe models without IDs which means state restoration fails because the recipes have new unique IDs every time the app is launched (there is a let id = UUID() in Recipe). The problem is in NavigationCookbook/Models/DataModel private let builtInRecipes: [Recipe] = { var recipes = [ "Apple Pie": Recipe( name: "Apple Pie", category: .dessert, ingredients: applePie.ingredients), Should be let builtInRecipes: [Recipe] = { var recipes = [ "Apple Pie": Recipe( id: UUID(uuidString: "E35A5C9C-F1EA-4B3D-9980-E2240B363AC8")!, name: "Apple Pie", category: .dessert, ingredients: Ingredient.fromLines(applePie)), And the same thing for all the other built-in recipes in the array. The builtInRecipes containing ids can be found in the Code tab in the Developer app for this samples WWDC session video: https://developer.apple.com/wwdc22/10054 I also submitted this as feedback FB11744612
Replies
0
Boosts
0
Views
1.3k
Activity
Nov ’22