Alec O
Alec O

Reputation: 1707

CGPoint(_,_) Requiring CGFloat Inputs on Linux

My Swift code runs fine in Xcode on my Mac, but when I deploy to my third-party Cloud hosting service built for server-side Swift I run into this problem. I am getting the error: Cannot convert value of type 'Int' to expected argument type 'CGFloat' when using CGPoint(x: Int, y: Int). I would rather use an integer over a float.

enter image description here

I believe that this is an issue with Swift specifically on Linux. In addition to this question, are there anyways to debug Swift on a Mac, but for a Linux environment? Also, what other inconsistencies does Swift for Linux have? I have found that arc4random is not supported and that Dispatch needs to be imported for any dispatch related code.

Upvotes: 0

Views: 190

Answers (1)

Martin R
Martin R

Reputation: 539765

On Linux (and other non-Apple platforms), CGPoint is defined in NSGeometry.swift as part of the swift-corelibs-foundation project.

As one can see in the source code, there is no initializer taking Int parameters, so you have to convert them explicitly:

let xVal: Int = ...
let yVal: Int = ...

let point = CGPoint(x: CGFloat(xVal), y: CGFloat(yVal))

Upvotes: 2

Related Questions