2

I want to use the Objective-C macros __LINE__ and __PRETTY_FUNCTION__ to log some information at runtime. There are many tools that can provide details to crash dumps, but in my case I want to analyse remote database entries, e.g. record which method made the entry and which operating system (Android or iOS).

I am not familiar with the macros __LINE__ and __PRETTY_FUNCTION__ and although they are working for my current build configuration (non-App Store), I am not sure if it will keep on working when the build configuration changes.

Will the information persist when making builds differently, such as a Release build that does not have debug symbols included?

And do App Store builds using bitcode have an influence on this?

jscs
  • 63,694
  • 13
  • 151
  • 195
Wayne
  • 3,359
  • 3
  • 30
  • 50
  • BTW: you can "Process for..." and show the preprocessor output in Xcode. That'll show you what the post-precompiler source looks like. It is... wordy.... and quite informative. – bbum Mar 03 '18 at 20:18

1 Answers1

4

These macros are replaced during preprocessing with the real values, before compilation.

I am not sure if it's a good idea to use them in production but they will definitely work. They don't need debug symbols (they are part of the source code) and they don't care how you sign the application package.

Sulthan
  • 128,090
  • 22
  • 218
  • 270
  • 1
    Maybe in Objective-C (and only for methods) printing `cmd` and `[self class]` is a better solution. `[[NSThread currentThread] callStackSymbols]` can add additional information, i. e. for indenting. Just an idea … – Amin Negm-Awad Mar 03 '18 at 11:33
  • @AminNegm-Awad `cmd` and `__FUNCTION__` are the same in practive. `callStackSymbols` would not work without debugging symbols. – Sulthan Mar 03 '18 at 12:10
  • I referred to `callStackSymbols` for indention, which does not need debug symbols. `cmd` is independent of flags, compilation mode and so on, so using it, makes the whole Q meaningless. (However, IIRC, you can have full flavoured debug symbols independently of the compilation mode.) – Amin Negm-Awad Mar 03 '18 at 13:12