6

What is the use of FOUNDATION EXPORT in Objective-c?

So I have:

KError.h

FOUNDATION_EXPORT NSString *const KAPPErrorDomain;

enum {
    KPUnexpectedError = -1,
};

KError.m:

#import "KError.h"

NSString *const KAPPErrorDomain = @"com.kexample.myapp";

I assume that when you use Foundation_export in this case, it is to be able to use a variable in another file?

So that in KService.m, I cam reference KAppErrorDomain without any problem?

Kermit the Frog
  • 3,949
  • 7
  • 31
  • 39

1 Answers1

7

Yes. FOUNDATION_EXPORT is a macro that expands to extern (or extern "C" in a C++ file), and that is the keyword to declare a variable that is shared across source files (better: shared across "translation units").

See How do I use extern to share variables between source files? for many good answers why extern is necessary and how it works.

Community
  • 1
  • 1
Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382