In Xcode 7, Swift cannot autocomplete Objective-C code

I am working in an Objective-C project and am trying to introduce Swift. I have header bridges that work, so the code compiles, however, none of the Objective-C classes are auto-complete.

I tried:

  • Logout Xcode / Restarting
  • Removing the DerivedData folder in (~ / Library / Developer / Xcode / DerivedData)
  • Deleting a file in ~ / Library / Caches / com.apple.dt.Xcode
  • Simulator Type Change

However, these suggestions did not work for me.

Autocomplete works fine for UIKit, etc., as well as for my other Swift code. This is only the Objective-C code displayed by the bridge title, which will not be autocomplete.

Any suggestions?

+5
source share
3 answers

I think I understood this:

Our project has several goals, and most files belong to several goals. If you want autocomplete, the header that you import must be imported into the bridge header for each target that the file belongs to.

When I imported the header that I needed in each header, autocomplete started working as expected.

Update. It looks like you can consolidate up to one bridge header if this setting works for your project. This will prevent you from updating multiple headers every time you want to add imports.

+5
source

Thanks to joel.d's answer, I fixed the same issue in my project.

In the header of the bridge, I had the line:

#import "BTData.h" 

Please note that it was some kind of sdk from cocoa pod, and recently we updated all the containers, so this is probably due to the fact that problems with autocompletion are running. Replacing the above line below, the problem is fixed, and now all obj-c classes are autocomplete in fast files.

 #import <Braintree/BTData.h> 
+2
source

I recently ran into this problem with a big objc project. Hope this helps someone.

For me, autocomplete worked before in this project, but then a crash for all object c-classes / methods started. However, the project is still drafted without problems.

I ended up commenting on all existing import data in the bridge header and adding a simple test class for which automatic processing worked. Then uncomment each of the other imports until I highlighted which one caused the problem.

For example, my headline basically looked like this:

 #import "MyClass.h" #import "MyOtherClass.h" #import "SomeThirdPartyModule.h" etc... 

I have done this:

 #import "SimpleTestClassWithOneMethod.h" // #import "MyClass.h" // #import "MyOtherClass.h" // #import "SomeThirdPartyModule.h" 

And autocomplete started working for SimpleTestClass when used from Swift.

Then he began to uncomment the other classes from the bridge header until it worked. The import that caused this problem was a third-party structure, not sure why this caused the problem, but I just pulled what I needed from this specific header for my quick code and imported it separately.

+1
source

Source: https://habr.com/ru/post/1235315/


All Articles