UIImageView Extensions

Set of helper methods defined on UIImageView to simplify displaying a user's image.

For most cases, you will likely have one or more UIImageViews defined for a view controller where you will want to display a user's profile pic and/or cover photo, such as on a profile screen. The methods in this extension simplify that by taking an image id, making a request for that image, and if successful, set an image view's image property to that image.

Methods

dxImage

func dxImage(
    forImageId imageId: String?, 
    _ completion: ((_ error: Error?) -> Void)?
) -> Void

Request an image by its id and if successful, set as the image view's image property.

Parameter

Type

Description

forImageId

String?

String representing an image's id.

completion

(Error?) -> Void

The closure invoked when the request finishes.

error

Error?

The error returned for an unsuccessful request.

dxProfilePic

func dxProfilePic(
    forImageId imageId: String?, 
    _ completion: ((_ error: Error?) -> Void)?
) -> Void

Request a user's profile pic by its id. If the request fails, sets the image property to a default image; otherwise, sets the image property to the user's profile pic.

Parameter

Type

Description

forImageId

String?

The id of a user's profile pic.

completion

(Error?) -> Void

The closure invoked when the request finishes.

error

Error?

The error returned for an unsuccessful request.

dxCoverPhoto

func dxCoverPhoto(
    forImageId imageId: String?, 
    _ completion: ((_ error: Error?) -> Void)?
) -> Void

Request a user's cover photo by its id. If the request fails, sets the image property to a default image; otherwise, sets the image property to the user's cover photo.

Parameter

Type

Description

forImageId

String?

The id of a user's cover photo.

completion

(Error?) -> Void

The closure invoked when the request finishes.

error

Error?

The error returned for an unsuccessful request.

Last updated