@import not working for me


#1

I am reading the “For the More Curious” section at the end of Chapter 2. Since I am truly among the more curious, I wanted to try out @import. Unfortunately the compiler is complaining it doesn’t know about this.

Betraying my curiousity, I went and started researching @import and how it’s supposed to work. I found that I am supposed to be able to enable it with LLVM 5 build settings (and that it automatically links the frameworks you @import – cool). Unfortunately the two settings that are related, Enable Modules and Link Frameworks Automatically, do not appear for me. This is likely related to the fact that @import isn’t working for me at all…

Which begs the question, why not? Before you ask, I have Version 5.0.2 (5A3005) and Software Update is not giving me the option to get a newer version, so I assume it is the latest non-beta. I also checked the version of LLVM I have:

Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

So, I’m at a loss. What’s needed to get this?


#2

Oh, and this is a brand new project, created for the purposes of working through Chapter 2.


#3

How did you type it in, I mean the import directive?

Like this:

@import "FooBar.h"

Or this:

#import "FooBar.h"

#4

Like this:

Quotes don’t seem to do anything, and the examples I’ve found look like the above:

http://clang.llvm.org/docs/Modules.html#objective-c-import-declaration


#5

Oops! I totally misunderstood the question.


#6

Ok, I figured it out. When you start a new iOS project ‘Enable Modules’ is set yes by default. When you start a new MacOS project it’s set to no by default. I was missing the setting because there’s more than one section’s worth of Apple LLVM 5.0 settings available, and I didn’t scroll down far enough to see the rest of them. Once I enabled it, ‘@import Foundation’ works fine.

I’m not sure this counts as errata or not. This chapter clearly mentions modules, so it’s reasonable someone would want to try them in this project, and yet the current defaults in XCode 5.0.2 ensure that it won’t compile. I will post it in the errata and see if it gets round-filed. :wink: