Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective C @import for modules does it replace #import?

The new syntax in Objective-C in Xcode 5 is @importto import a framework.

See question for details. Advantage is that you don't have to include the framework in project avoiding linker errors, you don't need to add quotes and .h to just the name of the framework, it is faster for precompiled headers, and you have a namespace that protects you from accidentally renaming a symbol. All nice additions.

My question is, for your own files, for example MyFancyViewController.h, do you continue to use #import or does @import completely replace it? Also, can I define my own modules easily? Just looks more messy having both syntaxes in the same file.

like image 606
possen Avatar asked Feb 15 '23 03:02

possen


1 Answers

for you including of your project files do you continue to use #import or does @import completely replace it?

@import, so far, is for Apple frameworks only, so at the time of writing you still have to use #import for anything else.
The good news is that, if you opt-in, any #import will be implicitly replaced for you by the compiler, so you don't need to convert your previous code to benefit from modules.

Also, can I define my own modules easily?

Yes and no.
Yes, it's easy, but...
...no you cannot, since this feature is currently not supported for non-Apple frameworks.

To define your own module - if you could - you would need to do:

export MyAwesomeModule:
public:
   // methods and whatever you want to export
like image 141
Gabriele Petronella Avatar answered Feb 23 '23 12:02

Gabriele Petronella