11

I am a bit confused as when we should use FOUNDATION_EXPORT in objective-c and what the purpose of that is? Can anyone explain in layman terms? Thanks!

Jeremy Haning
  • 211
  • 3
  • 9
  • 2
    See these two links: http://stackoverflow.com/questions/10953221/foundation-export-vs-extern, http://stackoverflow.com/questions/1041866/in-c-source-what-is-the-effect-of-extern-c – JuJoDi Oct 04 '13 at 23:58
  • also: http://stackoverflow.com/questions/17668018/when-to-use-uikit-extern-vs-just-extern/17669269#17669269 – justin Oct 05 '13 at 05:11
  • duplicate of http://stackoverflow.com/q/10953221/1698467 – skywinder Jun 05 '15 at 15:13

2 Answers2

4

When we should use FOUNDATION_EXPORT in Objective-c

Whenever you are importing foundation framework in Objective-C. It is the best practice to use FOUNDATION_EXPORT instead of extern. Because NSObjCRuntime.h in Foundation framework it includes c and c++ library. So for default visibility of the c and c++ symbols it compiles accordingly for making it more compatible.

Purpose of using FOUNDATION_EXPORT instead of extern:

1) Visible Symbolity

2) Compatibility to other source code.

Rivera
  • 10,792
  • 3
  • 58
  • 102
Hussain Shabbir
  • 14,801
  • 5
  • 40
  • 56
2

When to use FOUNDATION_EXPORT?

Never.

FOUNDATION_EXPORT is an undocumented implementation detail of Apple's system frameworks so you should not use it at all.

Nikolai Ruhe
  • 81,520
  • 17
  • 180
  • 200
  • 1
    What does means "**undocumented**"? Look in `NSObjCRuntime.h` + more detailed answer about here: http://stackoverflow.com/a/10953284/1698467 – skywinder Jun 05 '15 at 15:11
  • I see Matt Thomson (AFNetworking creator) uses that in his libraries. Should we still not use it at all in 2017? Thanks! – ppalancica Sep 05 '17 at 17:19