Apparently CGFloat is no longer a value in SWiftUI

simply trying to define a published variable of type CGFloat...


import Combine

import Foundation


class Percentage:ObservableObject {

@Published var percentage : CGFloat = 0

}

yields the error: Use of undeclared type 'CGFloat'


YAAAAA! another basic error that should NEVER occur

what a piece of junk.

Long gone are the days of Steve Jobs and quality products that worked with apple.

Now, it's problem after problem, error after error.

The people at apple need to get back to basics, and build quality products that work.

They need a hard lesson in TIME IS MONEY! I don't have the money or the time to fight with editors or basic things that should just work!

Accepted Reply

This does not cause error:

import Combine
import Foundation
import CoreGraphics

class Percentage:ObservableObject {
@Published var percentage : CGFloat = 0
}


Neither this:

import Combine
import UIKit

class Percentage:ObservableObject {
@Published var percentage : CGFloat = 0
}


Or:

import SwiftUI

class Percentage:ObservableObject {
@Published var percentage : CGFloat = 0
}


The fact `CGFloat` is not included in the Foundation framework might still be a big issue for you,

but, for me, the two-letter prefix `CG` is well representing its state, it is a part of Core Graphics framework.

  • Well, the real crap is XCode saying:

    Cannot find type 'CGFloat' in scope; did you mean to use 'CGFloat'?

    Clicking on "Fix" seems to substitute the CGFloat I typed with the golden CGFloat letters XCode is suggesting... just to later say:

    Cannot find type 'CGFloat' in scope; did you mean to use 'CGFloat'?

    XCode 13.3.1

Add a Comment

Replies

This does not cause error:

import Combine
import Foundation
import CoreGraphics

class Percentage:ObservableObject {
@Published var percentage : CGFloat = 0
}


Neither this:

import Combine
import UIKit

class Percentage:ObservableObject {
@Published var percentage : CGFloat = 0
}


Or:

import SwiftUI

class Percentage:ObservableObject {
@Published var percentage : CGFloat = 0
}


The fact `CGFloat` is not included in the Foundation framework might still be a big issue for you,

but, for me, the two-letter prefix `CG` is well representing its state, it is a part of Core Graphics framework.

  • Well, the real crap is XCode saying:

    Cannot find type 'CGFloat' in scope; did you mean to use 'CGFloat'?

    Clicking on "Fix" seems to substitute the CGFloat I typed with the golden CGFloat letters XCode is suggesting... just to later say:

    Cannot find type 'CGFloat' in scope; did you mean to use 'CGFloat'?

    XCode 13.3.1

Add a Comment

You need to import SwiftUI in order for that to work