Replace “CGFloat” with “CGFloat”??

XCode 6 usually gives helpful error messages, but this one was highly cryptic and if I had not found the solution I’d probably be banging my head against a wall now. This is the message:

Use of undeclared type ‘CGFloat’; did you mean to use ‘CGFloat’?

Ehh… what? This tweet also wonders about it… I triple checked if I misspelled something, but no. The suggestion to “replace CGFloat with CGFloat” seems odd, and does not fix the problem (duh). This is the error-producing code:

Fortunately the solution is very simple. It turns out that CGFloat belongs to the UIKit class, which is not present in a custom (Swift) class and that is where the error happened. So to fix it: just import UIKit.

I just found out that a Swift Playground does not produce the error, just the Swift File.

Hope this saves you some headaches… :-)

4 Responses to “Replace “CGFloat” with “CGFloat”??”

  1. SShahid says:

    found this helpful. Really saved me a headache.

  2. KG says:

    Thanks! This was driving me nuts. So simple, yet so elusive…

  3. Geoff says:

    Thank you!!! I wish I’d found this post a couple of days earlier. I shudder to think of the hours I wasted chasing down false hypotheses.

  4. Pradeep says:

    Thank you

Leave a Reply

Your email address will not be published. Required fields are marked *