Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift using obj-c classes. Runs but gives undeclared type errors

Tags:

ios

swift

xcode6

I have a project written mostly in objective-c. Adding a swift file that is a UIViewController that uses some other of our custom classes. I have these all listed in the bridging file.

When I run it in the emulator, everything is ok. But when I go to open the swift file in the editor, it then complains about undeclared types, as if I didn't add them in the bridging file. If I run in the simulator, those errors go away, and they stay away until I edit this swift file again.

Is there something I do not understand about the timing of the bridging header? Is this just an annoying bug in Xcode or am I doing something wrong?

like image 966
Jason Hocker Avatar asked Sep 16 '14 21:09

Jason Hocker


1 Answers

It appears like this is one of the many Xcode's bugs related to swift. I would recommend you to do following steps:

  1. check if your bridging header is set correctly: go to project -> Build settings -> find "Objective-C Bridging Header" line under "Swift Compiler - Code Generation". The path to your bridging header should be written there.

  2. check if there are no errors in your bridging file (unlikely but still).

all your imports should be written in form like:

#import "MyFile.h"

or

#import <MyLib/MyFile.h>
  1. Clean project: go to Product -> Clean or press Cmd + Alt + K
  2. (this and next steps solves most of the Xcode bugs related to swift) clean project's Derived Data folder:

go to window -> organizer -> select "Projects" in the top pane -> select your project in the left pane -> click on "Delete" next to the "Derived Data" label

  1. (if previous didn't helped) quit Xcode and go to "~/library/Developer/Xcode/DerivedData/" and delete everything from it. Then Restart project.
like image 148
Nikita Arkhipov Avatar answered Oct 31 '22 17:10

Nikita Arkhipov