Post

Replies

Boosts

Views

Activity

Can't access child entries of SwiftData class
When I tried to use a working project with iOS 18 installed on my device, it wouldn't work anymore and crash right away. Before with iOS 17 it was working fine. I can't access child variables that are saved in an Array in a parent object in SwiftData. The error is always somewhere in these hidden lines: { @storageRestrictions(accesses: _$backingData, initializes: _title) init(initialValue) { _$backingData.setValue(forKey: \.title, to: initialValue) _title = _SwiftDataNoType() } get { _$observationRegistrar.access(self, keyPath: \.title) return self.getValue(forKey: \.title) } set { _$observationRegistrar.withMutation(of: self, keyPath: \.title) { self.setValue(forKey: \.title, to: newValue) } } } The child classes are also inserted and saved into the modelContext when created and set to the parent instance, but I also can't fetch them via modelContext.fetch() - Error here is: Thread 1: EXC_BREAKPOINT (code=1, subcode=0x243a62a4c) Maybe there is a problem with the relationship between two saved instances. The parent instances are saved correctly and it was working in iOS 17. The problem is similar to these two cases: https://forums.developer.apple.com/forums/thread/762679 https://forums.developer.apple.com/forums/thread/738983 I changed the logic after I reviewed these threads, as I am now linking the parent and child instances, that got rid of one warning in the console. button.canvas = canvas modelContext.insert(button) canvas.buttons = [button] But in the end those threads were not enough for me to find a fix for my problem. A small project can be found here: https://github.com/DonMalte/SwiftDataTest
2
0
208
1w
Can't access chart playlists for a specific genre
I am trying to offer my users a wide variety of playlists, like Apple Music does in the "explore" section. I fetched the charting playlists for the current storefront, but that's as far as I get. For example, I fetch the top charts genres first. If a user selects a genre I want to display the playlists for this genre, so I call the charts endpoint with the genre as the id but I can't get a response. path = "/v1/catalog/\(storefrontID)/charts" components.queryItems = [ URLQueryItem(name: "types", value: "playlists"), URLQueryItem(name: "chart", value: "most-played") ] if let id = id { let genreQuery = URLQueryItem(name: "genre", value: id) components.queryItems?.append(genreQuery) } Even weirder, I get exactly one genre "Musik" (which isn't a genre) with identifier "34" and storefrontId "de" where it works and I get my playlists. All other genre return empty responses. I try to use AppleMusic API with MusicKit as an addition, but there doesn't seem to be a solution for this problem either.
3
2
1.2k
Sep ’22