I have started working on a project, that has been developed by some guys over last few years and this is how they set up CocoaLumberjack:
There are the following 2 files:
LogLevelInfo.h
static const int ddLogLevel = DDLogLevelInfo;
#define VAR_LOG_VERBOSE __unused
LogLevelVerbose.h
static const int ddLogLevel = DDLogLevelVerbose;
#define VAR_LOG_VERBOSE
Those 2 files are imported by different other classes, depending on which Log Level should be used.
Now I started to extract some of the sourcecode to a Framework because it has to be done. This is where I started to get troubles. Some of the Source Code already uses CocoaLumberjack for logging, so I had to put the LogLevelInfo.h and LogLevelVerbose.h into the Framework as well. So far, so good. The Framework project is compilable and doesn't throw any errors.
I have removed the LogLevelVerbose.h and LogLevelInfo.h from my parent project and integrated my Framework using Cocoapods. Now Xcode tells me that ddLogLevel
has been redefined: Redefinition of ddLogLevel
(shows error in LogLevelVerbose.h in my Pods subdir. Development Pods subdir, to be honest).
Can someone please explain why there was no problem of redefining ddLogLevel within the Xcode project and why it is a problem when using it within a framework in another project? Unfortunately I need CocoaLumberjack in the Framework as well as in the parent project :-(.
Then I found this in CocoaLumberjack.h:
* Step 1:
* Import the header in your implementation or prefix file:
*
* #import <CocoaLumberjack/CocoaLumberjack.h>
*
* Step 2:
* Define your logging level in your implementation file:
*
* // Log levels: off, error, warn, info, verbose
* static const DDLogLevel ddLogLevel = DDLogLevelVerbose;
*
* Step 2 [3rd party frameworks]:
*
* Define your LOG_LEVEL_DEF to a different variable/function than ddLogLevel:
*
* // #undef LOG_LEVEL_DEF // Undefine first only if needed
* #define LOG_LEVEL_DEF myLibLogLevel
*
* Define your logging level in your implementation file:
*
* // Log levels: off, error, warn, info, verbose
* static const DDLogLevel myLibLogLevel = DDLogLevelVerbose;
But after changing the name to myLibLogLevel, everything stayed almost the same. Xcode kept telling me Redefinition of myLibLogLevel