Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Xcode 7, Swift can't autocomplete Objective-C code

I'm working in an Objective-C project and trying to introduce Swift. I've got bridging headers working so that the code compiles, however none of the Objective-C classes are being picked up by autocomplete.

I've tried:

  1. Quitting Xcode / Restarting Computer
  2. Deleting the DerivedData folder at (~/Library/Developer/Xcode/DerivedData)
  3. Removing the file at ~/Library/Caches/com.apple.dt.Xcode
  4. Changing Simulator type

However, these suggestions didn't work for me.

Autocomplete works fine for UIKit, etc., and for my other Swift code. It's only the Objective-C code exposed by the bridging header that will not autocomplete.

Any suggestions?

like image 643
Wyatt Avatar asked Nov 05 '15 17:11

Wyatt


2 Answers

I think I figured this one out:

Our project has multiple targets, and most of the files belong to multiple targets. If you want autocompletion, the header you are importing has to be imported in the bridging header for every target the file belongs to.

When I imported the header I wanted in each bridging header, autocompletion started working as expected.

Update: Seems like you can consolidate down to one bridging header if that setup works for your project. That would prevent you having to update multiple headers every time you wanted to add an import.

like image 193
Wyatt Avatar answered Sep 21 '22 15:09

Wyatt


Thanks to joel.d answer, I've fixed the same problem in my project.

In bridging-header I had line:

#import "BTData.h"

Please note that it was some sdk from cocoa pod, and recently we have updated all pods, so probably thats when autocompletion problems has started. Replacing above line with this one below fixed the issue and now all obj-c classes are autocompleting in swift files.

#import <Braintree/BTData.h>
like image 41
gogel Avatar answered Sep 20 '22 15:09

gogel