The Situation:
Working from a new project: iOS > Application > Game > SpriteKit, Swift, iPhone
Here I've written a function in my GameScene.swift
to accept a hex color value and alpha double. I am going by the Swift documentation, and referencing an elegant solution I saw online. I've noticed this exact code compiles, runs and displays the proper color for a build target of iPhone5 in the simulator.
But...
The exact same project wont even compile when my build target is set for iPhone5s.
Could not find an overload for 'init' that accepts the supplied arguments.
The function:
// colorize function takes HEX and Alpha converts then returns aUIColor object
func colorize (hex: Int, alpha: Double = 1.0) -> UIColor {
let red = Double((hex & 0xFF0000) >> 16) / 255.0
let green = Double((hex & 0xFF00) >> 8) / 255.0
let blue = Double((hex & 0xFF)) / 255.0
var color: UIColor = UIColor( red: Float(red), green: Float(green), blue: Float(blue), alpha:Float(alpha) )
return color
}
The related call in didMoveToView
:
override func didMoveToView(view: SKView) {
// blue background color
self.backgroundColor = colorize( 0x003342, alpha:1.0)
}
Admittedly I am very new to iOS development, but I am wondering what is going on to cause the compiler not to find this initializer?
EDIT: putting up a github momentarily
A quick gist with related files... the only one I've edited is GameScene.swift
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…