Reputation: 309
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:
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?
Upvotes: 5
Views: 3182
Reputation: 31
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>
Upvotes: 2
Reputation: 1631
I recently ran into this issue with a large mostly-objc project. Hopefully this helps somebody.
For me autocomplete had been working before in this project but then began to fail for all objective c classes / methods. The project still compiled with no issues though.
I ended up commenting out all of the existing imports in the bridging header and adding a simple test class, for which auto complete worked. Then uncommenting each of the other imports until I isolated which one caused the problem.
For example my header basically looked like this:
#import "MyClass.h"
#import "MyOtherClass.h"
#import "SomeThirdPartyModule.h"
etc...
I did this:
#import "SimpleTestClassWithOneMethod.h"
// #import "MyClass.h"
// #import "MyOtherClass.h"
// #import "SomeThirdPartyModule.h"
And autocomplete started working for SimpleTestClass when used from Swift.
Then started uncommenting other classes from the bridging header until it worked. The import that caused the problem was some third party framework, not sure why it caused an issue but I just pulled out what I needed from that particular header for my swift code and imported it separately.
Upvotes: 1
Reputation: 309
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.
Upvotes: 5