Reputation: 1423
I've been using a tool sbconstants to create external constants out of the Storyboard Identifiers and Reuse Identifiers in my Xcode project.
I have #imported the header than contains all the declarations for these constants into the project's .pch file, and use these constants when calling methods such as performSegueWithIdentifier: and instantiateViewControllerWithIdentifier:. The project can build perfectly fine and run without issues, but Xcode logs an error for each use of these constants it finds, with the message "Use of undeclared identifier ..."
Further complicating the issue, it seems that the constants are being indexed, since cmd-clicking on them brings me to the constant's declaration in my constants .m file. Additionally, it seems like Xcode isn't logging an error for use of these constants unless I open the file where they are used in Xcode (i.e. files that use these constants don't have any errors attributed to them until I open up the file to edit).
I don't think there is actually any issue with the declarations of the constants themselves (since the app builds and runs perfectly fine), but obviously Xcode thinks there's an issue. I've tried aggressively cleaning my project and deleting the derived data in hopes of fixing this issue, but that hasn't solved the problem. Has anyone else come across this or a similar issue before and found a way to get Xcode to recognize the constants properly?
Upvotes: 2
Views: 3501
Reputation: 1753
I was also having same kind of problem but with a little difference, today I created an objective-C empty file named Constants.m, and the Constants.h file was created by my peer (may be) 3 Months ago. I was trying to use kConstant in App which is declared in .m file, but it throwing me “undeclared Identifier kCrashlyticsId”, later after digging into deep codeI found solution.
Solution: I added some values (NSString constant) to Constants.m file.
.m file
NSString *const kCrashlyticsId = @“somejunktextwhichIdidnotunderstood”;
NSString *const kAppName = @“hereIhavemyAppName”;
and in Constants.h, I referenced that constant using extern keyword.
.h file
extern NSString *const kCrashlyticsId;
extern NSString *const kAppName;
which eventually solves my issue.
I tried deleting Derived data, quitting xCode, restarting system and all that, but all that din’t worked for me.
Hope this solution helps others.
Thanks.
Upvotes: 0
Reputation: 149
I had similar issues too that resolved by cleaning the project, restarting xCode and rebuilding it. You may also try removing the #import from the precompiled header and explicitly importing the constants whenever they are needed.
Upvotes: 1