Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What can be the cause of "use of undeclared identifier LOG_LEVEL_VERBOSE" message

I'm trying to configure cocoalumberjack and when I've added ddLogLevel set to LOG_LEVEL_VERBOSE XCode throws "use of undeclared identifier" error. Why is that? How to avoid?

enter image description here

like image 722
Lukasz 'Severiaan' Grela Avatar asked Aug 04 '14 06:08

Lukasz 'Severiaan' Grela


2 Answers

This question indicates that clearing DerivedData and restarting Xcode solves this kind of error.

However you should not include variables in the pre-compiled header as it will be included in every source file and prefix files are somewhat complicated compared to normal header files.

Better is to have use a Constants.h file which contains:

extern int ddLogLevel;

and #import that into your prefix file.

Then create an Constants.m with:

int ddLogLevel =
#ifdef DEBUG
                 LOG_LEVEL_VERBOSE;
#else
                 LOG_LEVEL_ERROR;
#endif

This way there is only one instance of ddLogLevel and it can be easily changed at runtime if necessary.

See this question for hints about prefix file best practices.

like image 123
Droppy Avatar answered Nov 06 '22 22:11

Droppy


What solved it for me was changing #import <CocoaLumberjack/CocoaLumberjack.h> to @import CocoaLumberjack;, when using Xcode 8.0 for an Objective-C project.

like image 41
mllm Avatar answered Nov 06 '22 23:11

mllm