JayVDiyk
JayVDiyk

Reputation: 4487

Could not find an overload 'init' that accept the supplied argument

        var segmentedControlImages: [AnyObject] = [UIImage(named: "likeIcon"), UIImage(named: "dislikeIcon")];

why does this code produce this error? Its really confusing

Any help please

Upvotes: 0

Views: 95

Answers (1)

rintaro
rintaro

Reputation: 51911

Because, UIImage(named:) returns Optional. And Optional<UIImage> is not convertible to AnyObject.

You can force unwrap them:

var segmentedControlImages: [AnyObject] = [
    UIImage(named: "likeIcon")!,
    UIImage(named: "dislikeIcon")!
]

Upvotes: 2

Related Questions