In iOS 8.0 I had this enum:
enum Direction:CGPoint {
case Top = "{0, -1}"
case Right = "{1, 0}"
case Down = "{0, 1}"
case Left = "{-1, 0}"
case TopLeft = "{-1, -1}"
case TopRight = "{1, -1}"
case DownLeft = "{-1, 1}"
case DownRight = "{1, 1}"
case None = "{0, 0}"
}
extension CGPoint: StringLiteralConvertible {
public static func convertFromStringLiteral(value: StringLiteralType) -> CGPoint {
return CGPointFromString(value)
}
public static func convertFromExtendedGraphemeClusterLiteral(value: StringLiteralType) -> CGPoint {
return convertFromStringLiteral(value)
}
}
Now this worked exactly the way I wanted, I had to use strings because simply case Top = CGPoint(x:0,y:1)
does not work.
I use it like this ex:
1. var Dir:Direction = .None
2. self.center.AddWithPoint(self.Dir.rawValue.multiply(CGFloat(Speed)))
3. bullet.Dir = .Right
Now thats how Ive used the enum before 8.1, but now it is not longer allowed.
Now I get a ton of errors saying things like this:
. Type 'CGPoint' does not conform to protocol 'StringLiteralConvertible'
. 'String' is not convertible to 'CGPoint'
So is there any way I can make it work as before? Any answer or suggestion are appreciated!