Building Spotify App in Swift 5 & UIKit - Part 6 (Xcode 12, 2021, Swift 5) - Build App
public func getFeaturedPlaylists(completionHandler: @escaping((Result<FeaturedPlaylistsResponse, Error>)-> ())) {
createRequest(with: URL(string: Constants.baseAPIURL + "/browse/featured-playlists?limit=2"), type: .GET) { request in
URLSession.shared.dataTask(with: request) { data, response, error in
guard let data = data, error == nil else {
completionHandler(.failure(APIError.failedToGetData))
return
}
do {
let result = try JSONDecoder().decode(FeaturedPlaylistsResponse.self, from: data)
completionHandler(.success(result))
} catch {
print(error.localizedDescription)
completionHandler(.failure(error))
}
}
.resume()
}
}