Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ASMusicKit 프레임워크로 분리 #25

Merged
merged 9 commits into from
Nov 13, 2024
38 changes: 38 additions & 0 deletions alsongDalsong/ASMusicAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import MusicKit

struct ASMusicAPI {

/// search 결과를 Assong으로 변환 하여 배열로 리턴하는 함수
/// 노래 검색화면에 기본으로 뜨는 row 개수가 6개이므로 별다른 지정 없으면 기본값 6으로 지정
func search(for text: String, _ maxCount: Int = 6) async -> [ASSong] {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P3: 함수의 첫시작은 붙여서 작성!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

해당파일은 adcbcdc 커밋에서 삭제됐습니다! public 붙이고 린트 수정해서 프레임워크로 옮겨놨어용!

let status = await MusicAuthorization.request()

switch status {
case .authorized:
do {
var request = MusicCatalogSearchRequest(term: text, types: [Song.self])
request.limit = maxCount
request.offset = 1

let result = try await request.response()
let asSongs = result.songs.map { song in
ASSong(title: song.title, artistName: song.artistName)
}
return asSongs
} catch {
print(String(describing: error))
return []
}
default:
print("Not authorized to access Apple Music")
return []
}
}
}

struct ASSong: Equatable {
let title: String
let artistName: String
}