Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not find an overload for “init” that accepts the supplied arguments in Swift

I am trying to figure out how to translate this in Swift and I am also having this error: "Could not find an overload for “init” that accepts the supplied arguments". Any suggestion appreciated. Thanks.

var pageImages:[UIImage] = [UIImage]()
pageImages = [UIImage(named: "example.png"), UIImage(named: "example2.png")]
like image 211
hightech Avatar asked Nov 30 '22 18:11

hightech


2 Answers

Confirming what matt says:

in xCode 6.0 this does work:

images = [UIImage(named: "steps_normal"), UIImage(named: "steps_big")]

but in xCode6.1 values should be unwrapped:

images = [UIImage(named: "steps_normal")!, UIImage(named: "steps_big")!]
like image 125
Eugene Braginets Avatar answered Dec 03 '22 08:12

Eugene Braginets


Unwrap those optionals. A UIImage is not the same as a UIImage?, which is what the named: initializer returns. Thus:

var pageImages = [UIImage(named: "example.png")!, UIImage(named: "example2.png")!]

(Unless, of course, you actually want an array of optional UIImages.)

like image 28
matt Avatar answered Dec 03 '22 06:12

matt