33

I created a new Swift project and tried to import my existing Objective C code into the Swift project. Everything is going fine except, Xcode 6 Beta 5 is complaining about CGFloat UIFont CGSize...The error I see is

Expect a type

and

Unknown type name 'CGFloat'

right next to some of my methods. I thought Swift should be friendly with Objective C and accept all my Objective C code but unfortunately, this is not the case.

Any Idea?, suggestions, or comments, I would appreciate it. Thanks.

Amal T S
  • 3,327
  • 2
  • 24
  • 57
xiaowoo
  • 2,248
  • 7
  • 34
  • 45

4 Answers4

82

just Add this in which you are facing error

#import <UIKit/UIKit.h>
Mohit Tomar
  • 5,173
  • 2
  • 33
  • 40
15

Swift

import CoreGraphics

or

import UIKit

If you'd like. (UIKit includes CoreGraphics)

Andrew
  • 36,676
  • 11
  • 141
  • 113
4

If you tried to import existing Objective-C code than first of all you create one Objective-C header file in your Swift project. . .

after clicking that, editor asked for creating Bridging-Header, you must click yes:

enter image description here

these creates yourSwiftProjectName-Bridging-Header.h file . . .

Now, import your existing objective-c file in your project & simply import your header file in Bridging-Header.h file for example,

if your objective-c file is viewController.h & viewController.m than in Bridging-Header.h file write one line code:

#import "viewController.h"

I think, this code works for you . . .

Binarian
  • 12,296
  • 8
  • 53
  • 84
iHardikTrivedi
  • 559
  • 3
  • 16
  • Hi iHart, thanks for the reply. Actually dragged the files from my old project to the new and I did click Yes when it ask me to confirgure and Objective-C bridging header...But it did not solve the problem for me – xiaowoo Aug 10 '14 at 18:04
  • 1
    I think, after creating Bridging header file.. create new objective-c header .h & also create implementation .m file in you new project . . . after that you can select whole code (cmd+a) & copy from your old objective-c file and paste into new created .h & .m file . . . I hope, these works – iHardikTrivedi Aug 11 '14 at 02:56
0

In multi module envirompment it can be because of wrong setting .modulemap[About] or umbrella header does not include it

yoAlex5
  • 29,217
  • 8
  • 193
  • 205