-1

Since Xcode 6 and the introduction of modules, there is no need for precompiled headers anymore. I have always been using a custom logging method which also logs the file, method and line number it was on. This method was defined in the precompiled header. Where should I define the method now we shouldn't use them anymore, without me having to define it in a bunch of files?

#define YBLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
Community
  • 1
  • 1
yoeriboven
  • 3,393
  • 2
  • 22
  • 40

2 Answers2

2

Your #define have a little mistake.

You are define YBLog(fmt,...) to YBLog itself. You need to write NSLog instead of YBLog in the macro definition.

You need to define it like:

#define YBLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)

EDIT:

If you need to access the same on so many files, you have two option.

  1. Add a pch file by yourself and add the declaration in it (I'm doing the same)
  2. Define it in a header file and include it anywhere you want
Midhun MP
  • 90,682
  • 30
  • 147
  • 191
0

Create a common.h file and put it in there. Import it where necessary.

Earl Grey
  • 7,129
  • 5
  • 35
  • 57