leoli1 leoli1 - 1 year ago 168
Swift Question

SceneKit Scene Background Contents UIImage Array Error

I am developing a game for iOS using

. When I want to set a skybox to the scene I get an error:

var path = "skyboxes.scnassets/skybox"
self.scene!.background.contents = [
UIImage(named: path+"_right.png"),
UIImage(named: path+"_left.png"),
UIImage(named: path+"_top.png"),
UIImage(named: path+"_bottom.png"),
UIImage(named: path+"_front.png"),
UIImage(named: path+"_back.png"),

Error: Cannot assign a value of type [UIImage?] to a value of type

I tried to cast the array to a
or an
array but that doesn't work.

Could anyone help me?

Answer Source

contents is of type [AnyObject!]; so, the following should work:

scene!.background.contents =
    UIImage(named: path+"_right.png") as UIImage!              
    UIImage(named: path+"_left.png") as UIImage!,
    UIImage(named: path+"_top.png") as UIImage!,
    UIImage(named: path+"_bottom.png") as UIImage!,
    UIImage(named: path+"_front.png") as UIImage!,
    UIImage(named: path+"_back.png") as UIImage!,
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download