leoli1 leoli1 - 7 months ago 65
Swift Question

SceneKit Scene Background Contents UIImage Array Error

I am developing a game for iOS using

SceneKit
. 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
AnyObject!


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

Could anyone help me?

Answer

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!,
]
Comments