Instance Method

loadImage(completionHandler:)

Loads the image property for a completed achievement.

Declaration

iOS, Mac Catalyst, tvOS
func loadImage(completionHandler: ((UIImage?, Error?) -> Void)? = nil)
macOS
func loadImage(completionHandler: ((NSImage?, Error?) -> Void)? = nil)

Parameters

completionHandler

A block to be called when the download is completed.

The block receives the following parameters:

image

The downloaded image. If an error occurred, this value is nil.

error

If an error occurred, this error object describes the error. If the operation completed successfully, this value is nil.

Discussion

Loading and displaying achievements using a custon interface is a two-step process, with the first step being to call the loadAchievementDescriptions(completionHandler:) method. The second step is to call the loadImage(completionHandler:) method for each achievement the user has completed. Your game should display the placeholder image until the image is successfully downloaded. After the block is called, the description’s image property holds the same image object that is returned to the block.

When this method is called, it creates a new background task to handle the request. The method then returns control to your game. Later, when the task is complete, Game Kit calls your completion handler. The completion handler is always called on the main thread.

In macOS, this class method returns an NSImage object but otherwise works identically.

See Also

Working with Achievement Images

class func incompleteAchievementImage() -> UIImage

A common image for incomplete achievements.

class func placeholderCompletedAchievementImage() -> UIImage

A common image for completed achievements.