Posts

Post not yet marked as solved
0 Replies
85 Views
If they had used .task they could have removed the class LocationsHandler: ObservableObject and simply done: struct ContentView: View { @State var lastLocation: CLLocation? var body: some View { VStack { ... } .task { let updates = CLLocationUpdate.liveUpdates() for try await update in updates { if let loc = update.location { self.lastLocation = loc } } } And saved themselves about 20 or so lines of code. .task was added in the year before so it isn't the case that it wasn't available to the CoreLocation team yet. To wrap async/await in a Combine's ObservableObject is very strange. They could have also used @AppStorage instead of UserDefaults and saved another few lines. To be honest this is some of the strangest SwiftUI code I've seen.
Posted
by malc.
Last updated
.
Post not yet marked as solved
0 Replies
426 Views
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...
Posted
by malc.
Last updated
.
Post not yet marked as solved
0 Replies
732 Views
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.
Posted
by malc.
Last updated
.
Post marked as solved
2 Replies
1.8k Views
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.
Posted
by malc.
Last updated
.
Post not yet marked as solved
1 Replies
1.5k Views
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
Posted
by malc.
Last updated
.
Post not yet marked as solved
0 Replies
969 Views
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
Posted
by malc.
Last updated
.
Post not yet marked as solved
3 Replies
1.5k Views
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.
Posted
by malc.
Last updated
.
Post not yet marked as solved
0 Replies
585 Views
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.
Posted
by malc.
Last updated
.
Post not yet marked as solved
4 Replies
1.8k Views
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)
Posted
by malc.
Last updated
.
Post marked as solved
1 Replies
1.2k Views
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.
Posted
by malc.
Last updated
.
Post not yet marked as solved
2 Replies
1k Views
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?
Posted
by malc.
Last updated
.
Post not yet marked as solved
5 Replies
2.2k Views
Please explain how and when the state should be transferred from split VC to tab controller when traits change from regular to compact. Please also consider then the middle “supplementary” column is in use. Please confirm we should no longer use adaptivity API given any showing alert or popover would likely be lost or should those also be in the state? Sample code of the relevant parts of the Shortcuts app would be very useful as this is a very difficult design pattern and it seems it is essential for cross platform apps targeting iPhone/iPad/Catalyst.
Posted
by malc.
Last updated
.
Post not yet marked as solved
0 Replies
855 Views
I noticed something in the Structure your app for SwiftUI previews video, at 15:56 he says: "And now we can tell SwiftUI to format the text for this name at exactly the right time. This is as easy as defining a formatter..." https://developer.apple.com/videos/play/wwdc2020/10149/?time=950 var body: some View { &#9;&#9;let formatter = PersonNameComponentsFormatter() &#9;&#9;formatter.style = .long &#9;&#9;Text("\(name, formatter: formatter)") } It seems to me that this is not that easy for 2 reasons. I was under the impression we are not supposed to create reference types like a formatter object in the view body, or anywhere in the View that is not property wrapped. Supposedly it causes a heap allocation and slows down SwiftUI's updates. Maybe Swift has been improved to now allocate reference types on the stack instead of the heap and this is now OK? Given that PersonNameFormatter is dependent on the locale, surely if the locale is changed then the View body will not be recomputed because the View is not detecting a change. Is the Text View doing its own observing of the locale changes? If 1 is ok should the View simply subscribe to the locale changing some how? How would that be done? Or should we make an ObservableObject for the formatter? It can track the locale did change notification and set a new formatter as a @Published property. Use @StateObject in the View for this object so SwiftUI will know to recompute the body when there is a new formatter after a locale change so the person's name can be re-formatted. Or is my guess at 3 correct that Text handles the locale change for us?
Posted
by malc.
Last updated
.
Post not yet marked as solved
0 Replies
848 Views
The video discusses limits to background pushes. I'm unable to finish developing my app that uses NSPersistentCloudKitContainer on iOS 14 because I believe background push notifications are being limited by the system so I am unable to test how the app behaves when it is suspended and a background push arrives. In fact I cannot get any background pushes to arrive at all, however pushes do arrive when the app is running in the foreground. Is there perhaps a development entitlement or launch param to override all limits so I can finish my app? And if not, can this feature be added please?
Posted
by malc.
Last updated
.