Questions tagged [cgfloat]

A CGFloat is the basic CoreGraphics type for all floating-point values in the Cocoa and Cocoa Touch UI frameworks.

A CGFloat is the basic CoreGraphics type for all floating-point values in the Cocoa and Cocoa Touch UI frameworks.

CGFloat is defined in the CGGeometry Reference of CoreGraphics, which defines structures for geometric primitives and functions that operate on them. Depending on your platform, a CGFloat is either 32 or 64 bits.

Use this tag when asking questions on CGFloat value types themselves, or CoreGraphics functions which use them.

207 questions
3
votes
1 answer

How to convert Any to CGFloat in Swift 3

I need Any to CGFloat. But, I got a fatal error. Why can't assign Any to CGFloat? How to convert? let lx = ix as! CGFloat Error message: Thread 1:EXC_BAD_INSTRUCTION (code=EXC_l386_INVOP, subcode=0x0) 0x1040dcbf1 <+1329>: movsd -0xc0(%rbp), %xmm0…
Haru
  • 63
  • 1
  • 4
3
votes
1 answer

How do I discover the lowest negative possible CGFloat?

I know of these values: CGFloat.infinity, which is greater than CGFloat.greatestFiniteMagnitude, which is greater than CGFloat.leastNormalMagnitude, which is greater than CGFloat.leastNonzeroMagnitude, which is greater than 0 but it stops there...…
Ky -
  • 30,724
  • 51
  • 192
  • 308
3
votes
0 answers

CGFloat <-> Double

Writing graphics code in UIKit is a PITA. The "nominal" floating point type for Swift is Double. But most of the UIKit graphics code uses CGFloat which seems to be either Double or Float based on the chip in my phone. I find myself having to…
Travis Griggs
  • 21,522
  • 19
  • 91
  • 167
3
votes
3 answers

Binary Operator + Cannot be Applied to Operands of Type CGfloat int

I am having the same problem as earlier with a different line of code; but this time, I wasn't able to fix it with the same approach as last time: var Y : Int = 0 var X : Int = 0 @IBOutlet var ball : UIImageView! ball.center =…
Dan A
  • 209
  • 1
  • 3
  • 12
3
votes
1 answer

CGFloat cannot be initialized with Float

I have a function that I have written for a Sprite Kit application using Swift. Xcode currently errors on building, claiming that a CGFloat() cannot be initialized. Here is my code: func someFunction () { var x:Float = 5.0 return…
Grayson Pike
  • 397
  • 1
  • 4
  • 13
3
votes
1 answer

NSNumber floatValue not equal to NSNumber value

First post here. Having a problem with NSNumber's floatValue method -- somehow, it returns an imprecise number. Here's the problem: I store a bunch of NSNumbers in an array, like this: NSArray *a = [NSArray arrayWithObjects: [NSNumber…
Mirkules
  • 1,709
  • 15
  • 21
3
votes
2 answers

What is the equivalent of NSNotFound for floats

What if I have a method that returns a CGFloat and that method could not find an expected number, I would like to return something like NSNotFound, but that is an NSInteger. Whats the best practice for this ?
bobmoff
  • 2,415
  • 3
  • 25
  • 32
3
votes
2 answers

Changing an Int to a CGFloat in Swift to return heightForRowAtIndexPath tableview function

I am sure that I am missing something really simple, but I just can't get it to work. I will try to explain better what I am doing to try to help others if they have this same issue. This was my function: func tableView(tableView: UITableView,…
Nate4436271
  • 860
  • 1
  • 10
  • 21
3
votes
3 answers

Swift enum raw value: not working with CGFloat = -1.0

What does this not work? enum Aspect : CGFloat { case Clockwise = 1.0 case Anticlockwise = -1.0 } On Anticlockwise line I'm told that 'raw value for enum case must be a literal'
Tchelyzt
  • 161
  • 1
  • 10
3
votes
1 answer

Swift conversions, CGFloat to Integer

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…
Mahmud Ahmad
  • 171
  • 3
  • 18
3
votes
3 answers

Swift type conversions: Getting color data as CGFloat to an NSData of 8bit integers

For posterity: this question is referencing iOS8 Beta 4 I'm trying to get an NSData instance full of 24 bit colors. The bytes would be [r,g,b, r,g,b, ...] so 3 bytes per color, all tightly packed together. Problem is that I need some Uint8s to use…
Alex Wayne
  • 178,991
  • 47
  • 309
  • 337
3
votes
1 answer

CGFloat: call rintf() when Float and rint() when Double

When architecture is 32 bit then CGFloat is Float. In this case I would like to invoke rintf() When architecture is 64 bit then CGFloat is Double. In this case I would like to invoke rint() I currently do a cast to Double and then invoke rint() func…
neoneye
  • 50,398
  • 25
  • 166
  • 151
3
votes
2 answers

How do I get the minimum value of two CGFloats in Swift?

I have this code that should return the minimum value of two CGFloat values: var boundsSize:CGSize = scrollView.bounds.size var imageSize:CGSize = imageView.bounds.size var xScale:CGFloat = boundsSize.width / imageSize.width var…
Amit Erandole
  • 11,995
  • 23
  • 65
  • 103
3
votes
1 answer

Incompatible integer to pointer conversion assigning to 'CGFloat *' (aka 'float *') from 'int'

I'm having a problem with CGFloat. What I am trying to do is to set a value for the X of a UIScrollView to do some actions when the user change page using a UIButton to do that. This is the error Xcode gives to me: Incompatible integer to pointer…
Aluminum
  • 2,932
  • 5
  • 35
  • 63
3
votes
1 answer

Why does CGPointEqualToPoint simply perform (p.x == p.x && p.y == p.y)?

Since comparing floats is such a difficult and debated issue I was surprised to see that CGPointEqualToPoint and the other CG comparison methods simply do this: CG_INLINE bool __CGPointEqualToPoint(CGPoint point1, CGPoint point2) { return point1.x…
CodeSmile
  • 64,284
  • 20
  • 132
  • 217