Simple wrapper for the iTunes Search API written in Swift.
To be able to use the iTunes Search API wrapper you need an iTunes client.
iTunes(session: URLSession = URLSession.shared, debug: Bool = false)
When debug
is enabled, you get some information about the url which will be requested.
For the most basic search you only have to provide a search term and a completion handler. The result of the search will be passed as a Result containing either the successfully decoded JSON or a SearchError.
itunes.search(for: "Castle") { result in
// handle the Result<Any, SearchError>
}
When you are looking for something specific you can add a specific media type.
itunes.search(for: "Castle", ofType: .tvShow(.tvSeason)) { result in
// handle the Result<Any, SearchError>
}
Each Media
type can take an additional parameter of type Entity
. This entity parameter specifies the return type. In the example above we are only looking for TV Seasons of the show Castle.
Similar to the search you can use the lookup function. The lookup function takes a LookupType
and a completion handler.
itunes.lookup(by: .id("12345")) { result in
// handle the Result<Any, SearchError>
}
Both search()
and lookup()
can take an addtitional parameter of type Option
. There you can specify information like limit, language or country.
- Swift 4.0
- iOS 8.4
- tvOS 9.0
github "svenbacia/iTunesSearchAPI"
iTunesSearchAPI is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "iTunesSearchAPI"
You can also add the specific target manually to your project.
Created and maintained by @svenbacia
iTunesSearchAPI is available under the MIT license. See the LICENSE file for more info.