Skip to content

Commit

Permalink
🚨 Drop support for Xcode 13 and compiler version < 5.7
Browse files Browse the repository at this point in the history
  • Loading branch information
rudrankriyam committed Aug 3, 2023
1 parent bc6499c commit 0ac7e8d
Show file tree
Hide file tree
Showing 19 changed files with 92 additions and 156 deletions.
2 changes: 0 additions & 2 deletions Sources/MusadoraKit/Add Resources/CreatePlaylist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Foundation
@available(macOS 14.0, *)
public extension MLibrary {

#if compiler(>=5.7)
/// Creates a playlist in the user’s music library.
///
/// - Parameters:
Expand Down Expand Up @@ -41,7 +40,6 @@ public extension MLibrary {
@available(macCatalyst, unavailable) static func createPlaylist(with name: String, author: String? = nil, description: String? = nil, items: Songs) async throws -> Playlist {
try await MusicLibrary.shared.createPlaylist(name: name, description: description, authorDisplayName: author, items: items)
}
#endif

/// Creates a playlist in the user’s music library.
///
Expand Down
2 changes: 0 additions & 2 deletions Sources/MusadoraKit/Catalog/CatalogChart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by Rudrank Riyam on 22/06/22.
//

#if compiler(>=5.7)
/// Represents types of music catalog charts available in Apple Music.
///
/// These types can be songs, albums, playlists or music videos.
Expand Down Expand Up @@ -260,4 +259,3 @@ extension MCatalog {
return response
}
}
#endif
5 changes: 0 additions & 5 deletions Sources/MusadoraKit/Catalog/CatalogGenre.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public extension MCatalog {
/// Fetch top genres from the Apple Music catalog.
/// - Returns: Top `Genres`.
static func topGenres() async throws -> Genres {
#if compiler(>=5.7)
if #available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *) {
let request = MusicCatalogResourceRequest<Genre>()
let response = try await request.response()
Expand All @@ -46,10 +45,6 @@ public extension MCatalog {
let storefront = try await MusicDataRequest.currentCountryCode
return try await topGenres(for: storefront)
}
#else
let storefront = try await MusicDataRequest.currentCountryCode
return try await topGenres(for: storefront)
#endif
}

/// Fetch top genres from the Apple Music catalog for a particular storefront.
Expand Down
8 changes: 4 additions & 4 deletions Sources/MusadoraKit/Catalog/CatalogRecordLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

public extension MCatalog {
/// Fetch a record label from the Apple Music catalog by using its identifier.
///
/// - Parameters:
/// - id: The unique identifier for the record label.
/// - properties: Additional relationships to fetch with the record label.
Expand All @@ -23,8 +24,8 @@ public extension MCatalog {
return recordLabel
}

#if compiler(>=5.7)
/// Fetch a record label from the Apple Music catalog by using its identifier with all properties.
///
/// - Parameters:
/// - id: The unique identifier for the record label.
/// - Returns: `RecordLabel` matching the given identifier.
Expand All @@ -38,9 +39,9 @@ public extension MCatalog {
}
return recordLabel
}
#endif

/// Fetch multiple record labels from the Apple Music catalog by using their identifiers.
///
/// - Parameters:
/// - ids: The unique identifiers for the record labels.
/// - properties: Additional relationships to fetch with the record labels.
Expand All @@ -53,8 +54,8 @@ public extension MCatalog {
return response.items
}

#if compiler(>=5.7)
/// Fetch multiple record labels from the Apple Music catalog by using their identifiers with all properties.
///
/// - Parameters:
/// - ids: The unique identifiers for the record labels.
/// - Returns: `RecordLabels` matching the given identifiers.
Expand All @@ -64,5 +65,4 @@ public extension MCatalog {
let response = try await request.response()
return response.items
}
#endif
}
8 changes: 4 additions & 4 deletions Sources/MusadoraKit/Catalog/CatalogSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ public extension MCatalog {
}
}

#if compiler(>=5.7)
public extension MCatalog {
/// Fetch top results and search suggestions from the Apple Music catalog by using a query term.
///
/// - Parameters:
/// - term: The entered text for the search.
/// - types: The types of music items to include in the search.
/// - limit: The number of objects returned.
/// - Returns: `MusicCatalogSearchSuggestionsResponse` that returns different top music items and suggestions.
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *)
static func searchSuggestions(for term: String,
types: [MCatalogSearchType],
limit: Int? = nil) async throws -> MusicCatalogSearchSuggestionsResponse {
types: [MCatalogSearchType],
limit: Int? = nil) async throws -> MusicCatalogSearchSuggestionsResponse {
let searchTypes = types.compactMap { $0.type }
var request = MusicCatalogSearchSuggestionsRequest(term: term, includingTopResultsOfTypes: searchTypes)
request.limit = limit
Expand All @@ -130,6 +130,7 @@ public extension MCatalog {
}

/// Fetch search suggestions from the Apple Music catalog by using a query term.
///
/// - Parameters:
/// - term: The entered text for the search.
/// - types: The types of music items to include in the search.
Expand All @@ -144,4 +145,3 @@ public extension MCatalog {
return response.suggestions
}
}
#endif
5 changes: 1 addition & 4 deletions Sources/MusadoraKit/Catalog/MCatalogSearchType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,12 @@ public enum MCatalogSearchType {
extension MCatalogSearchTypes {
public static var all: Self {
var types: Self = [.songs, .albums, .playlists, .artists, .stations, .recordLabels]
#if compiler(>=5.7)

if #available(iOS 15.4, macOS 12.3, tvOS 15.4, watchOS 9.0, *) {
types += [.musicVideos, .curators, .radioShows]
return types
} else {
return types
}
#else
return types
#endif
}
}
2 changes: 0 additions & 2 deletions Sources/MusadoraKit/History/RecentlyPlayed.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import Foundation

#if compiler(>=5.7)
public extension MHistory {
@available(iOS 16.0, macOS 13.0, tvOS 16.0, watchOS 9.0, *)
static func recentlyPlayed(limit: Int? = nil) async throws -> MusicItemCollection<RecentlyPlayedMusicItem> {
Expand Down Expand Up @@ -49,7 +48,6 @@ public extension MHistory {
return response.items
}
}
#endif

public extension MHistory {
/// Fetch the recently played resources for the user.
Expand Down
25 changes: 10 additions & 15 deletions Sources/MusadoraKit/Library/LibraryAlbum.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,23 @@ public extension MLibrary {
}
}

#if compiler(>=5.7)
/// Fetch multiple albums from the user's library by using their identifiers.
///
/// - Parameters:
/// - ids: The unique identifiers for the albums.
/// - Returns: `Albums` matching the given identifiers.
@available(iOS 16.0, tvOS 16.0, watchOS 9.0, macOS 14.0, macCatalyst 17.0, *)
static func albums(ids: [MusicItemID]) async throws -> Albums {
var request = MusicLibraryRequest<Album>()
request.filter(matching: \.id, memberOf: ids)
let response = try await request.response()
return response.items
}
#else
static func albums(ids: [MusicItemID]) async throws -> Albums {
let request = MLibraryResourceRequest<Album>(matching: \.id, memberOf: ids)
let response = try await request.response()
return response.items
if #available(iOS 16.0, macOS 14.0, macCatalyst 17.0, tvOS 16.0, watchOS 9.0, *) {
var request = MusicLibraryRequest<Album>()
request.filter(matching: \.id, memberOf: ids)
let response = try await request.response()
return response.items
} else {
let request = MLibraryResourceRequest<Album>(matching: \.id, memberOf: ids)
let response = try await request.response()
return response.items
}
}
#endif

#if compiler(>=5.7)
/// Access the total number of albums in the user's library.
Expand Down Expand Up @@ -131,7 +128,6 @@ public extension MLibrary {
}
}

#if compiler(>=5.7)
@available(iOS 16.0, tvOS 16.0, watchOS 9.0, macOS 14.0, macCatalyst 17.0, *)
public extension MHistory {
/// Fetch recently added albums from the user's library sorted by the date added.
Expand Down Expand Up @@ -162,4 +158,3 @@ public extension MHistory {
return response.items
}
}
#endif
129 changes: 60 additions & 69 deletions Sources/MusadoraKit/Library/LibraryPlaylist.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,100 +37,92 @@ public extension MLibrary {
}
}

#if compiler(>=5.7)
/// Fetch all playlists from the user's library in alphabetical order.
///
/// - Parameters:
/// - limit: The number of playlists returned.
/// - Returns: `Playlists` for the given limit.
@available(iOS 16.0, tvOS 16.0, watchOS 9.0, macOS 14.0, macCatalyst 17.0, *)
static func playlists(limit: Int? = nil) async throws -> Playlists {
let request = MusicLibraryRequest<Playlist>()
let response = try await request.response()
return response.items
}
#else
static func playlists(limit: Int? = nil) async throws -> Playlists {
var request = MLibraryResourceRequest<Playlist>()
request.limit = limit
let response = try await request.response()
return response.items
if #available(iOS 16.0, macOS 14.0, macCatalyst 17.0, tvOS 16.0, watchOS 9.0, *) {
let request = MusicLibraryRequest<Playlist>()
let response = try await request.response()
return response.items
} else {
var request = MLibraryResourceRequest<Playlist>()
request.limit = limit
let response = try await request.response()
return response.items
}
}
#endif

#if compiler(>=5.7)
/// Fetch multiple playlists from the user's library by using their identifiers.
///
/// - Parameters:
/// - ids: The unique identifiers for the playlists.
@available(iOS 16.0, tvOS 16.0, watchOS 9.0, macOS 14.0, macCatalyst 17.0, *)
static func playlists(ids: [MusicItemID]) async throws -> Playlists {
var request = MusicLibraryRequest<Playlist>()
request.filter(matching: \.id, memberOf: ids)
let response = try await request.response()
return response.items
}
#else
static func playlists(ids: [MusicItemID]) async throws -> Playlists {
let request = MLibraryResourceRequest<Playlist>(matching: \.id, memberOf: ids)
let response = try await request.response()
return response.items
if #available(iOS 16.0, macOS 14.0, macCatalyst 17.0, tvOS 16.0, watchOS 9.0, *) {
var request = MusicLibraryRequest<Playlist>()
request.filter(matching: \.id, memberOf: ids)
let response = try await request.response()
return response.items
} else {
let request = MLibraryResourceRequest<Playlist>(matching: \.id, memberOf: ids)
let response = try await request.response()
return response.items
}
}
}
#endif

#if compiler(>=5.7)
/// Access the total number of playlists in the user's library.
@available(iOS 16.0, tvOS 16.0, watchOS 9.0, macOS 14.0, macCatalyst 17.0, *)
static var playlistsCount: Int {
get async throws {
let request = MusicLibraryRequest<Playlist>()
let response = try await request.response()
return response.items.count
/// Access the total number of playlists in the user's library.
@available(iOS 16.0, tvOS 16.0, watchOS 9.0, macOS 14.0, macCatalyst 17.0, *)
static var playlistsCount: Int {
get async throws {
let request = MusicLibraryRequest<Playlist>()
let response = try await request.response()
return response.items.count
}
}
}
#else
/// Access the total number of playlists in the user's library.
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
static var playlistsCount: Int {
get async throws {
if let items = MPMediaQuery.playlists().items {
return items.count
} else {
throw MediaPlayError.notFound(for: "playlists")
/// Access the total number of playlists in the user's library.
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
@available(tvOS, unavailable)
@available(watchOS, unavailable)
static var playlistsCount: Int {
get async throws {
if let items = MPMediaQuery.playlists().items {
return items.count
} else {
throw MediaPlayError.notFound(for: "playlists")
}
}
}
}
#endif

/// Add a playlist to the user's library by using its identifier.
///
/// - Parameters:
/// - id: The unique identifier for the playlist.
/// - Returns: `Bool` indicating if the insert was successfull or not.
static func addPlaylistToLibrary(id: MusicItemID) async throws -> Bool {
let request = MAddResourcesRequest([(item: .playlists, value: [id])])
let response = try await request.response()
return response
}
/// Add a playlist to the user's library by using its identifier.
///
/// - Parameters:
/// - id: The unique identifier for the playlist.
/// - Returns: `Bool` indicating if the insert was successfull or not.
static func addPlaylistToLibrary(id: MusicItemID) async throws -> Bool {
let request = MAddResourcesRequest([(item: .playlists, value: [id])])
let response = try await request.response()
return response
}

/// Add multiple playlists to the user's library by using their identifiers.
///
/// - Parameters:
/// - ids: The unique identifiers for the playlists.
/// - Returns: `Bool` indicating if the insert was successfull or not.
static func addPlaylistsToLibrary(ids: [MusicItemID]) async throws -> Bool {
let request = MAddResourcesRequest([(item: .playlists, value: ids)])
let response = try await request.response()
return response
}
/// Add multiple playlists to the user's library by using their identifiers.
///
/// - Parameters:
/// - ids: The unique identifiers for the playlists.
/// - Returns: `Bool` indicating if the insert was successfull or not.
static func addPlaylistsToLibrary(ids: [MusicItemID]) async throws -> Bool {
let request = MAddResourcesRequest([(item: .playlists, value: ids)])
let response = try await request.response()
return response
}

}

#if compiler(>=5.7)
@available(iOS 16.0, tvOS 16.0, watchOS 9.0, macOS 14.0, macCatalyst 17.0, *)
public extension MHistory {
/// Fetch recently added playlists from the user's library sorted by the date added.
Expand Down Expand Up @@ -161,7 +153,6 @@ public extension MHistory {
return response.items
}
}
#endif

// MARK: - `LibraryPlaylist` methods
public extension MLibrary {
Expand Down
Loading

0 comments on commit 0ac7e8d

Please sign in to comment.