6

I'm struggeling with Modules in a project. Where I use @import I get "Use of '@import' when modules are disabled". But why are they disabled?

  • In my build settings I have "Enable modules (C and Objective-C)" set to Yes for all targets.
  • Setting "Link Frameworks Automatically" to Yes or No does not impact this (compile-time) error
  • Although the project used to have Objective-C++ and some C++ code, it doesn't anymore. Are there any project-settings I can have missed that were set because of this?
  • I have no more .pch files in the project, and the build settings have no mention of them
  • I use CocoaPods (0.39.0) with "use_frameworks!" and the modules I wish @import are from there. But the same error happens if I replace the '#import ' or '#import ' with '@import Foundation;' and '@import UIKit', so I expect this is not related
  • The project is from pre-iOS7 so I might have missed a setting that used to be on by default
  • The project requires iOS 8 and builds against iOS 9.2.

I realize that loading third-party modules will probably slow down the apps loading time. I'm converting to CocoaPods with use_frameworks! so that I can measure by how much. If it's not too bad, I'd like to use as I'm planning to move multiple swift-only parts of the codebase into their own frameworks (as open source coocapods)

I believe that this is not be a duplicate of other questions on SO since I've gone through the ones I found (big thank-you to this one), followed the links, re-watched WWDC'13 session 404, and read the related posts on Apples forums, so I believe I've done my homework. :-)

Community
  • 1
  • 1
niklassaers
  • 7,810
  • 18
  • 90
  • 141
  • Have you tried creating a new project with the relevant files and check if it works there? If it's working I suggest u compare each field in the build settings – Tomer Even Jan 06 '16 at 21:09

2 Answers2

4

In my project I have a bridging header to bridge from ObjC to Swift, and there is a generated header file to bridge from Swift to ObjC. It turns out that if the bridging header referenced headers where the implementation file referenced the bridge file from Swift to ObjC, module support is disabled. So be careful about what you put in your bridging file, and be careful about when you import the generated -Swift.h file.

niklassaers
  • 7,810
  • 18
  • 90
  • 141
0

Firstly go to the terminal and type xcode-select -p. It should say, /Applications/Xcode.app/Contents/Developer. If it doesn't, then type, sudo xcode-select -s /Applications/Xcode.app and hit enter and type in your password.

If that doesn't fix it, try deleting your project's derived data directory. Go to the Projects view and delete the derived data for your project. Then clean your build folder (command-shift-K). Run Analyze (command-shift-B) and resolve any issues in blue and yellow.

Now if @import is still not working, create a brand new XCode project. Verify that @import works in it. If it doesn't, then your XCode installation got screwed up probably, or your HDD is dying. Delete XCode and re-download it, see if that works. Restart into the recovery partition and see if you have some disk issues (unlikely, but hey).

If @import works in the new project, try taking all your from your current project and copying them into the new project. Make sure you have the latest version of cocoapods and then freshly install your pods into the new project.

If all of that doesn't fix it, you probably left an @end statement out somewhere or have a missing } ...

CommaToast
  • 9,468
  • 7
  • 46
  • 65
  • This is a project-issue across many computers, all where ```xcode-select -p``` is as you wrote above. Build & Analyse doesn't come up with anything. Creating a new project supports modules just fine. So the only alternative I know of so far is manually recreating the project, but that doesn't really teach me the reason why this happens. I've manually diffed project settings for the new project with the old, and I can find no differences. – niklassaers Jan 22 '16 at 09:50
  • Very weird. I have run into a few things like this where there is some kind of strange XCode bug. Could be a permissions issue in the project directory... check the Console logs? Also there is always that issue of whether you had the main project build settings selected, or the build settings of the target selected. Sometimes I have the main project selected instead of the build target, and as it turns out the target is set to override the project global setting (i.e. the target's build setting is in bold text). – CommaToast Jan 23 '16 at 02:54