Swift MusicKitプログラミング その7
Swift MusicKitプログラミング その7
Limit以上を取得
一度では取得出来ません。
処理としては
- 続きがあるか確認(hasNextBatch)
- 続きを取得(nextBatch(limit:))
Limit指定可能
Limitを指定しない場合は5
となります。
Task() {
print("\nExample 5 --------------------")
var request = MusicCatalogSearchRequest(term: "氷室京介", types: [Song.self])
request.limit = 25
let response = try await request.response()
var songs: MusicItemCollection<Song> = response.songs
songs.forEach({
print($0)
})
var countSongs = songs.count
while songs.hasNextBatch == true {
if let songsNext = try await songs.nextBatch(limit: 25) {
songs = songsNext
songs.forEach({
print($0)
})
countSongs = countSongs + songs.count
}
}
print("Songs count:\(countSongs)")
}
Example 5 -------------------- Song(id: "681932641", title: "KISS ME", artistName: "氷室京介") Song(id: "681186219", title: "ANGEL", artistName: "氷室京介") : : : : Song(id: "1447070924", title: "KISS ME Originally Performed By 氷室京介 (オルゴール)", artistName: "オルゴールサウンド J-POP") Song(id: "1446233601", title: "JEALOUSYを眠らせて Originally Performed By 氷室京介 (オルゴール)", artistName: "オルゴールサウンド J-POP") Songs count:431






