If I fetch a library playlist like the generated "Favorites" playlist via MusicKit like this
guard let initialTracks = try await playlist.with([.tracks]).tracks else {
return nil
}
I get a list of tracks like this:
...
TrackID: i.e5gmPS6rZ856
TrackID: i.4ZQMxU0OxNg0
TrackID: i.J198KH4P85K4
TrackID: i.J1AaRC4P85K4
TrackID: i.4BPqWt0OxNg0
TrackID: 4473570282773028026
TrackID: 4473570282773028025
TrackID: 4015088256684964387
TrackID: 4473570282773028024
TrackID: 7541557725362154249
TrackID: 4473570282773028027
I save the IDs for later use, but when I want to fetch them, only the ones with ids that starts with "i." work.
static func getLibrarySong(from id: String) async -> Song? {
var request = MusicLibraryRequest<Song>()
request.filter(matching: \.id, equalTo: MusicItemID(id))
do {
let response = try await request.response()
return response.items.first
} catch {
...
}
}
Or the Apple Music API endpoint :
static func getLibrarySongFromAPI(with id: String) async -> Song? {
guard let url = AppleMusicURL.getURL(for: .getSongById, id: id) else {
return nil
}
do {
let dataRequest = MusicDataRequest(urlRequest: URLRequest(url: url))
let dataResponse = try await dataRequest.response()
let response = try JSONDecoder().decode(SongsResponse.self, from: dataResponse.data)
return response.data.first
} catch {
...
}
}
Both functions above won't work for the non numeric like 4473570282773028024 so it seems the ID is wrong, but how do I make it work?
Otherwise I can fetch all the songs fine, in catalog or in the library, but these few songs can't be individually fetched, only with the try await playlist.with([.tracks])` fetch, that gets the whole playlist. But obviously this isn't always possible.
Thanks in advance!
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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
Topic:
App & System Services
SubTopic:
iCloud & Data
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.