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

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?

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.

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

Droppy’s post is correct and I recommend doing that, but I would like to address the question directly. There is a flaw in your code that may be resulting in the error.
LOG_LEVEL_VERBOSE is defined in DDLog.h. Your header file only imports DDLog.h if __OBJC__ is defined, but uses LOG_LEVEL_VERBOSE without this condition. Therefore if __OBJC__ is not defined, LOG_LEVEL_VERBOSE will be undefined.
Why would __OBJC__ not be defined? The prefix header is prepended to C, C++, Objective-C and Objective-C++ files. Since __OBJC__ is only defined for the latter two, if there are any C or C++ files in your project then the error will occur.
Knowing this, it is clear the ddLogLevel definition should be inside the #ifdef __OBJC__ check. However, you should do what Droppy said, and also make sure all Objective-C imports go inside the check.

For people who use "CocoaLumberjack 2.X" and still facing same issue after pod update, please try to import "DDLegacyMacros.h".
For prefix file users, try something like this :
#ifdef __OBJC__
...
...
#import <DDTTYLogger.h>
#import <DDLog.h>
#import <DDLegacyMacros.h>
#endif
Hope this helps someone else.

Related

Project-Swift.h file not found

I have a new Swift project with a few files, I've needed to add some Objc code.
In Build Settings, my Objective-C Generated Interface Header Name is MyProject-Swift.h
Product Module Name and Product Name are both MyProject.
My Objective-C Bridging Header is MyProject/MyProject-Bridging-Header.h
The contents of my Bridging Header are:
#ifndef MyProject_Bridging_Header_h
#define MyProject_Bridging_Header_h
#import "Blakey.h"
#endif
Blakey.h is pretty simple:
#import Foundation;
#import "MyProject-Swift.h"
#class KeyPair;
#interface Blakey: NSObject
- (void)createKeyPairForSeed:(NSString *)seed;
#end
And Blakey.m
#import <Foundation/Foundation.h>
#import "Blakey.h"
#implementation Blakey
- (void)createKeyPairForSeed:(NSString *)seed;
{
}
#end
(side note: I'm aware my function returns a void, that will be changed later once this issue is fixed so it returns an actual value)
Why is Xcode throwing an error at the #import "MyProject-Swift.h" in Blakey.h?
Project-Swift.h is a file auto generated by Xcode on successful compilation of the project. Catch here is the word successful compilation If your project has any compilation error Project-Swift.h file will not be generated. So in a way it becomes a deadlock. Bestway comment out all the lines that have compilation error and then manage to get it compile without any errors. Only after that Project-Swift.h will be generated.
Additional information, Once the Project-Swift.h file is generated if you open it and if you happened to see that your swift class is not imported there thats because Project-Swift.h imports only the classes that extends from NSObject So plain Swift classes will not be imported.
ISSUE:
You need to import Project-Swift.h in .m file and not .h file. So modify your Blakey as
#import <Foundation/Foundation.h>
#import "Blakey.h"
#import "MyProject-Swift.h"
#implementation Blakey
- (void)createKeyPairForSeed:(NSString *)seed;
{
}
Finally remove #import "MyProject-Swift.h" from Blakey.h
#import Foundation;
#class KeyPair;
#interface Blakey: NSObject
- (void)createKeyPairForSeed:(NSString *)seed;
#end
I had similar issue and almost ended up spending a whole day trying to figure out what wrong with my app.
So following the solution that's helped me :
Clear derived data
Create a class in swift with prefix of #objc for example #objc class mySwiftClass{...}
Build the project again
Et voila.. Should work now.
Why to add #objc?
this #objc prefix, tells the compiler to generate to your swift class a header file. it will add it to the "MyModule-Swift.h" file
I realize this is an old thread, but I had similar issues after adding a new target to a project. I solved it by adding a preprocessor macro (Build Settings -> Apple Clang - Preprocessing) only in said target and then importing the Swift.h file conditionally, like this:
#if DEV_VERSION
#import "Project_DEV-Swift.h"
#else
#import "Project-Swift.h"
#endif
My main target is called Project and the new target is Project DEV (the space is replaced with an underscore in the import), and the preprocessor macro is called DEV_VERSION.
After doing this, both targets build just fine.
<product_name>-Swift.h file not found
It is a kind of bridge(adapter) between Swift and Objective-C. This file contains Swift's API for Objective-C which was marked [#objc and #objcMembers].
You can work with types declared in Swift from within the Objective-C code in your project by importing an Xcode-generated header file.
The header's name is generated from a <product_name>-Swift.h
[Mixing Objective-C and Swift ]
I had a similar issue whereby it would have this issue for anything other than live.
I resolved the issue by hardcoding "Product module name" & "Product name" to my project name. This avoids the need to have preprocessor logic in every file that includes swift code as demonstrated in Pauli Kettunen's solution.

'PushmoteSDK/Headers/Pushmote.h' file not found when trying to use pushmote sdk

I am trying to follow the steps given here:
http://docs.pushmote.com/docs/import-pushmote-ios-sdk-swift
but I am getting this error: 'PushmoteSDK/Headers/Pushmote.h' file not found, when I try and build my app.
Its my Pushmote-Bridging-Header.h file that has this import statement and the file is clearly there, in project_dir/PushmoteSDK.framework/Headers/Pushmote.h
I have read about a few other header file not found error with xcode and the solutions seem to vary a lot, so I think it might have to do with the specific version of xcode. Perhaps someone has used pushmote with xcode7 before and can assist?
EDIT:
This is my Pushmote-Bridging-Header.h file found in /Users/alex/ios_projects/Monkey/Monkey/Pushmote-Bridging-Header.h
#ifndef Pushmote_Bridging_Header_h
#define Pushmote_Bridging_Header_h
#import "PushmoteSDK/Pushmote.h"
#endif /* Pushmote_Bridging_Header_h */
You should change import line like this;
#import "PushmoteSDK/Headers/Pushmote.h"
to
#import "PushmoteSDK/Pushmote.h"

Xcode "Missing Submodule" warning

I'm using Xcode6 GM to create a Coacoa Touch Framework (a new function in Xcode6), then this framework is included into my app.
Everything is fine (works fine), except that I get warnings in "#import". What is the root cause?
I ran into the same problem and eventually fixed it by adding my project headers into the umbrella header. When you create a new framework it should start with a single .h file titled by the project (in your case DirectProximityFramework.h).
Inside this file is a comment:
In this header, you should import all the public headers of your
framework using statements like #import <DirectProximityFramework/PublicHeader.h>
So just add your GeofencingHelper.h file in this file:
#import <DirectProximityFramework/GeofencingHelper.h>
This should remove all of your warnings!
Maybe, you can stop this warning by adding following line to "DirectProximityFramework.h"
#import <DirectProximityFramework/GeofencingHelper.h>
...etc
I suggest to check
[Target your framework] -> Build Phases -> Headers -> Public
In case if it is not your framework and there is nothing to do you can disable warning in such way
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wincomplete-umbrella"
#import <DirectProximityFramework/GeofencingHelper.h>
#pragma clang diagnostic pop
Note - it is not a fix, it just hide the problem.
I ran into this issue and all the solutions above didn't fit me, since the file wasn't supposed to be in the umbrella header.
So if this is your own framework and that particular file shouldn't be in the umbrella header, make sure it isn't marked public in the target membership section.
That fixed it for me.
I had same issue and my solution was..
When you create the framework project.Your project automatically "yourProjectName.h" file gets created, In this header file import class class.
In my case I am getting missing submodule 'MSFramework.MSLocationManager' [-Wincomplete-umbrella]this warning.
resolved by Just importing
#import <UIKit/UIKit.h>
# import "MSLocationManager.h"
//! Project version number for MSFramework.
FOUNDATION_EXPORT double MSFrameworkVersionNumber;
//! Project version string for MSFramework.
FOUNDATION_EXPORT const unsigned char MSFrameworkVersionString[];
here I just add the # import "MSLocationManager.h"in header file.
// In this header, you should import all the public headers of your framework using statements like
#import <GameworkSDK/GWObject.h>
like this:
#import <UIKit/UIKit.h>
#import <GameworkSDK/GWObject.h>
//! Project version number for GameworkSDK.
FOUNDATION_EXPORT double GameworkSDKVersionNumber;
//! Project version string for GameworkSDK.
FOUNDATION_EXPORT const unsigned char GameworkSDKVersionString[];
i had this problem cocoa pods
my solution was real simple but took forever for me to figure out.
when i ran $ pod install it generated a workspace for me in the same dir as my .xcodeproj file.
however i had already created a workspace to use as its parent directory.
so then i simply deleted my old workspace and went with the one that pods created
glhf!
Set header search path in your project setting:
TARGETS / Build Settings / Header Search Paths
"$PODS_CONFIGURATION_BUILD_DIR/[YOUR PROJ NAME]/[YOUR PROJ NAME].framework/Headers"
Now import the header file.
#import <DirectProximityFramework.h>

How can I declare a config.h file, add it to my App-Prefix.pch, and then use it globally in my app?

I want to create a Config.h file to house all my static const strings that should be global to my application.
I've created a new Config.h file, but there are a few things I'm unaware of.
1) How do I declare variables. A or B?
A)
#define hotelURLString4 = #"http://blah.herokuapp.com/api/v1/hotels/";
B)
static NSString * const hotelURLString2 = #"http://blah.herokuapp.com/api/v1/hotels/";
2) I can't seem to use this file. If I try to import the Config.h directly into a file of mine, I get a "Config.h file not found" error in xcode. If I include it in my AppName-Prefix.pch up at the top via...
#import <Availability.h>
#import "Config.h"
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
That does not seem to work either. How do I do this.
3) How do I access the variable declared/defined. Do I call Config.hotelURLString, or [Config hotelURLString]... or how do I access it?
===================================================================
============================ UPDATE ===============================
1) I created my header like this... am I not doing something correctly, because I tried again and it won't work either.
2) This is my AppName-Prefix.pch file.
#import <Availability.h>
#import "Config.h"
#import "MyHeader.h"
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
3) Here is my Project Navigator
To answer question 1, method B is probably better, although you should name your variable more like:
kHoteUrlString2
And preferably something more descriptive then just the numbers, but the main point here is the lower case k and the uppercase first letter. This is a C/ObjC naming convention for constants.
As for question 2, it sounds like your file isn't actually in the project. Some more details are needed to answer this part of the question, and I'll update my answer if the question has more details added.
As for question 3, you use the variable exactly as you would as if you had declared it at the top of whatever file you're using. Objective-C doesn't have namespaces.

OpenCV compiler error when using Stitcher under iOS

Whenever I try to use the OpenCV Stitcher class in iOS and I include the stitcher-header ( #include ) I end up with a compile error "Expected '{'" in exposure_compensate.hpp. Apparently the line
enum { NO, GAIN, GAIN_BLOCKS };
is causing some sort of error.
I am very new to openCV but using other functions like filter2d() work as expected. How can I resolve this?
Try
#import <opencv2/opencv.hpp>
then
#import <UIKit/UIKit.h>
Update: this answer only highlights the bare minimum fix of the problem, and perhaps the root cause: order of dependencies. Please refer to other answers for better code / setup that you put in your project.
In your project, create a Prefix Header, MyProject.pch, and set it in your project's build settings.
Then within that pch file, do something like this:
#ifdef __cplusplus
# include <opencv2/opencv.hpp>
# include <opencv2/stitching/detail/blenders.hpp>
# include <opencv2/stitching/detail/exposure_compensate.hpp>
#else
# import <Foundation/Foundation.h>
# import <UIKit/UIKit.h>
# import <Availability.h>
#endif
I also ran into this problem. As G. Führ ensure you include the opencv headers first. The easiest way to do this is add:
#ifdef __cplusplus
#include <opencv2/opencv.hpp>
#endif
near the top of the apps "Appname-Prefix.pch" header. This is a precompiled header and makes it easy to guarantee that your opencv header will be included before any of the apple headers.
//
// Prefix header
//
// The contents of this file are implicitly included at the beginning of every source file.
//
#import <Availability.h>
#ifndef __IPHONE_5_0
#warning "This project uses features only available in iOS SDK 5.0 and later."
#endif
#ifdef __cplusplus
#include <opencv2/opencv.hpp>
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
This means you won't accidentally include an apple header before this anywhere else in the app.
I had a similar issue and I solved editing directly the opencv-framework files involved (in your case compensate.hpp) and comment from them the definition of the NO enum case definition. In this case the file was blender.hpp, but compensate.hpp has the same structure
Hope this helps
I solved this issue by importing any Apple headers before those of OpenCV, as mentioned in the beginning of the header:
#if defined(NO)
# warning Detected Apple 'NO' macro definition, it can cause build conflicts. Please, include this header before any Apple headers.
#endif
Hope that helps.
In my case, I create a vertical image stitching app with openCV, error show as screenshot below. It is from exposure_compensate.hpp and blenders.hpp. From the error description, the top file is ../CVWrapper.mm, which is in my project instead of openCV pod project.
As above guys said, there is some conflict issue between C++ and Apple MACRO. And we should put C++ header above Apple header.
First, I try a workaround from internet, which said "replace NO with NO_EXPOSURE_COMPENSATOR = 0". This worked, but it modified openCV source code, I don't want to do that because I will not do version control on Pod files, then if other guys clone my repo/project, they will need to do the same modification on those source code.
Then, I follow the error message in Xcode, I did following changes in my CVWrapper.mm file. After that, those two error disappear.
// Before change
#import "CVWrapper.h"
#import "UIImage+OpenCV.h"
#import "stitching.h"
#import "UIImage+Rotate.h"
// After change
#import "stitching.h"
#import "CVWrapper.h"
#import "UIImage+OpenCV.h"
#import "UIImage+Rotate.h"

Resources