3

How do you convert a @IValue CGFloat to an Int?

I keep getting a cannot convert @IValue CGFloat to Integer with the following:

@IBOutlet var userObject : UIImageView


func returnYPosition(yPosition: Integer) -> Integer {
    return userObject.center.y
}
Shruti Thombre
  • 989
  • 4
  • 11
  • 27
Mahmud Ahmad
  • 171
  • 3
  • 18
  • 2
    Integer has been renamed to IntegerType. But I think you might be trying to return an Int not an IntegerType. So change the signature to func returnYPosition(yPosition: Int)->Int, etc. – user1790252 Aug 17 '14 at 02:18
  • A good solution can be found here: http://stackoverflow.com/questions/24029917/convert-float-to-int-in-swift – Steve Rosenberg Aug 17 '14 at 02:27
  • Thanks! I got it to work finally! Yeah, I was trying to get an Int, idk what I had it as Integer haha @user1790252 – Mahmud Ahmad Aug 17 '14 at 15:55
  • This helped me finally figure out how to change the type of variable! Thanks! @MinnesotaSteve – Mahmud Ahmad Aug 17 '14 at 15:55

1 Answers1

5

You need to pass Int types back and forth, and then just cast:

func returnYPosition(yPosition: Int) -> Int {
    return Int(userObject.center.y)
}
Nate Cook
  • 92,417
  • 32
  • 217
  • 178