@import "Unexpected" @ "in the program"

I upgraded the project to Xcode 5 and enabled modules in the build settings. However, I see the Unexpected '@' in program compiler error when I use @import .

 #ifndef __IPHONE_7_0 #warning "This project uses features only available in iOS SDK 7.0 and later." #endif #ifdef __cplusplus #import <opencv2/opencv.hpp> #endif #ifdef __OBJC__ @import SystemConfiguration; @import UIKit; 

Is this something else to do?

+26
ios ios7 xcode5
09 Oct '13 at
source share
4 answers

From the comment by @hw731 I think you are using @import :

old syntax for importing a framework:

 #import <UIKit/UIKit.h> 

but now you can use the new syntax:

 @import UIKit; 

you need to include module abstracts to use the @import keyword (it is enabled by default when creating a new project with Xcode 5):

enter image description here

Take a look here .

+64
09 Oct '13 at 13:29
source share

Received the same error, check the standard places:

  • Yes, I have the correct code syntax.
  • Yes, all settings "Apple LLVM 5.0 - Languages ​​- Modules" - YES. And in this project, and in each of its goals.
  • Yes, I use the workspace, but I checked that all projects have modules. Both projects and each of their goals.
  • Yes, verified. I have no funny "smart" quotes anywhere.
  • Yes, I checked that I am in header.h or file.m (not .mm / .c / .cpp / .hpp)

The problem was that the header file was imported into file.mm , which does not seem to support the new syntax of the @import module! Converted this header back to the old #import format and everything was fine.

+12
Feb 20 '14 at 22:25
source share

I also found that using the following code in the pch file:

 #ifdef __cplusplus #import <opencv2/opencv.hpp> #endif 

not compatible with @import .

+5
Oct 31 '13 at 11:11
source share

Same problem when I subclass UIActivity and write property in .m file as

 @property(nonatomic, strong)NSArray *activityItems; 

fixed by moving this property to a .h file.

0
Feb 11 '16 at 13:56 on
source share



All Articles