Skip to content

DataDragon Images

Antoine CLOP edited this page Aug 1, 2020 · 2 revisions

DataDragon Images

When it comes to displaying images in your application, LeagueAPI often provide you ImageWithUrl objects.
Here, you'll learn how to use them the most efficient way.

What is ImageWithUrl

It is a simple class composed of an URL and a method getImage(). The url is present only to let the developer create custom behavior in his application. However, most of the time, you only want the UIImage directly. Thus, you'll use getImage() and receive asynchronously the UIImage?. In addition, LeagueAPI will store this image in cache so that if you call getImage() a second time, it will be returned very quickly. The image will be nil if an error occurred during download.

Usage example

Here is an example of how to get a profile icon UIImage:

league.lolAPI.getProfileIcon(by: ProfileIconId(16)) { (profileIconInfo, errorMsg) in
    if let profileIconInfo = profileIconInfo {
        let imageWithUrl: ImageWithUrl = profileIconInfo.profileIcon
        imageWithUrl.getImage() { (image, errorMsg) in
            if let image = image {
                print("Success!")
            }
            else {
                print("Request failed cause: \(errorMsg ?? "No error description")")
            }
        }
    }
    else {
        print("Request failed cause: \(errorMsg ?? "No error description")")
    }
}
Clone this wiki locally