Consider the following code: let img = UIImage(named: "myString") if let img = img { mySCNMaterial.diffuse.contents = img