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
5
votes
1 answer

What's the best way to do math with CGFloats in swift?

I tried to do some simple UIView layout math in swift and tried the following line of code... var offset: CGFloat = (bounds.width / 2.0) - ((sortedSymptoms.count * bounds.height) / 2.0) and got the following error from the compiler: cannot invoke…
Mike Akers
  • 12,039
  • 14
  • 58
  • 71
5
votes
1 answer

Can I apply the same extension to many classes without copy paste?

Let's say I have this extension for CGFloat extension CGFloat { // common public var thrice: CGFloat { return self * 3.0 } public var twice: CGFloat { return self * 2.0 } public var half: CGFloat { return self * 0.5 } public var…
JP.
  • 544
  • 5
  • 20
5
votes
2 answers

Swift - Could not find an overload... & Cannot convert the expression's type

I was adapting to Swift an ObjectiveC method I found on the internet (maybe here, I can't remember it) and when I build it for iPad Air, it runs perfectly, but when I try to run it on an iPad 2 or iPad Retina it gives 4 errors (2 different errors,…
rulilg
  • 1,604
  • 4
  • 15
  • 19
5
votes
1 answer

Handling CGFloat with an NSScanner on arm64

Apparently CGFloat is double on arm64: #if defined(__LP64__) && __LP64__ # define CGFLOAT_TYPE double # define CGFLOAT_IS_DOUBLE 1 # define CGFLOAT_MIN DBL_MIN # define CGFLOAT_MAX DBL_MAX #else # define CGFLOAT_TYPE float # define CGFLOAT_IS_DOUBLE…
A-Live
  • 8,904
  • 2
  • 39
  • 74
5
votes
1 answer

CGFloat is showing an error

I have declared a CGFloat variable on my header file: @property (nonatomic)CGFloat *heightOfSection; Synthetized it on my implementation file, but it gives me an error trying to assign a value to it: // Set height of section …
mvasco
  • 4,965
  • 7
  • 59
  • 120
5
votes
2 answers

Comparing two equal CGFloat:s, getting positive (YES) result

Until now this has not been a problem but from about today I ran into a strange issue that does not happen all the time, but rarely, I'd say one time out of 50, or even less. I'm comparing two CGFloat:s like this: const CGFloat MYFIRSTFLOAT = /* get…
Jonny
  • 15,955
  • 18
  • 111
  • 232
5
votes
2 answers

Is there a performance diff using CGFloat with or without postfix .f in Objective-C

Should I be writing CGFloat values with postfix f or not? CGFloat fValue = 1.2; vs. CGFloat fValue = 1.2f; I know that this postfix define a float value. But is it necessary, does it make sense, are there any performance differences between using…
Borut Tomazin
  • 8,041
  • 11
  • 78
  • 91
4
votes
0 answers

Cast CGFloat to Int in extension BinaryFloatingPoint

FIXED IN SWIFT 4.2 Details Xcode 9.2, Swift 4 Code extension BinaryFloatingPoint { func toInt() -> Int { // Eror if remove this block (I do not know why) // if let value = self as? CGFloat { // return Int(value) …
Vasily Bodnarchuk
  • 24,482
  • 9
  • 132
  • 127
4
votes
2 answers

Cannot assign value of type CGFloat to NSLayoutConstraint

I am trying to set the bottom constraint to the height of the keyboard (and plus 4.0 for a bit of spacing). However For the first bit I am getting the following error; Cannot assign value of type CGFloat to NSLayoutConstraint I thought they were…
A.Roe
  • 973
  • 3
  • 15
  • 34
4
votes
1 answer

Why use Float(arc4random()) / 0xFFFFFFFF instead of drand()

I'm new to Swift and just saw this code used to generate a random angle degree in a tutorial. func random() ->CGFloat{ return CGFloat(Float(arc4random()) / 0xFFFFFFFF) } func random(#min: CGFloat, max:CGFloat) ->CGFloat{ return…
Andy Zhang
  • 153
  • 5
4
votes
2 answers

Use CGFloat instead of float? They don't do it

[I might be misunderstanding this entire topic, as I've grown up with languages that allow the dev to almost entirely ignore processor architecture, like Java, except in some particular cases. Please correct me if I have some of the concepts…
Dan Rosenstark
  • 68,471
  • 58
  • 283
  • 421
4
votes
1 answer

Set different row height in different sections (storyboard)

I have a tableview with multiple prototype cells that i designed in the storyboard, but i´m stuck with the height problem because my first cell is supose to be different from the second one and so on...I have different identifiers for each cell, and…
Japa
  • 632
  • 7
  • 30
3
votes
2 answers

What is CGFloat.leastNonzeroMagnitude equivalent in Obj-C

What is the equivalent of CGFloat.leastNonzeroMagnitude equivalent in Objective-C? I googled but could not find any answer.
3
votes
3 answers

How to round of CGFloat value

Possible Duplicate: NSNumberFormatter for rounding up float values Currently, I calculate the scaling factor by using : CGFloat scale = CGContextGetCTM(context).a; NSLog(@"SCALE : %f", scale); I receive a floating point value as : 0.124979,…
lifemoveson
  • 1,661
  • 8
  • 28
  • 55
3
votes
1 answer

CGFloat Incompatible types in initialization

Anyone see the issue here? double latDouble = [latString doubleValue]; double lngDouble = [lngString doubleValue]; CGFloat dist = [self calcDiffDistance:latDouble withPostLng:lngDouble]; // Incompatible types in initialization -…
jdog
  • 10,351
  • 29
  • 90
  • 165
1 2
3
13 14