Compiler issues: "Use of Undeclared Identifer" error with constants that still work - constants

I am using a Constants.h file to declare a lot of strings for resources like URLs and the like. This has always worked fine in the past, and in fact continues to work when I compile and run.
However the issue navigator shows errors (the red bangs) despite labeling them as "semantic issues" (which sounds more like a warning) and the code editor windows show them as well for lines like this:
[app openBrowserWithUrl:[NSURL URLWithString: kRequestInformationURL]];
The line in Constants.h looks like this:
static NSString * const kRequestInformationURL = #"http://www.myserver.com"; // uses SSL!
It's throwing up warnings/errors for all of my declarations in Constants.h. But it still compiles and runs fine! I have no clue what's going on here, but it's very annoying because my project now shows that I have lots of warnings/errors.
I should also add that this happens in the latest version (4.5.1) of Xcode on one of my Macs
and not the other, opening the exact same project file.
Another thing I should note: you usually only see these error/warnings when you click on the file to edit it after compiling.
UPDATE EDITED: I thought that I got these to go away by adhering to more strict constants declarations, as explained in this post: https://stackoverflow.com/a/539039/326398 however all the warnings (which, as I said before, are marked with error icons in Xcode) came right back. So mystery is still very much intact.

Thats happening when you use "false" variables, your NSString is declared as *"const", you cannot do that because const is actually an own Declaration for something in Xcode, simply change NSStrings variable name.

Related

Remote Swift Package: Xcode won't pause at this breakpoint because it has not been resolved [duplicate]

Shortly after updating to Xcode 13.2.1 I started seeing some weird behaviour of breakpoints. When I run an app (in a simulator) some of my breakpoints change their look and turn to dotted blue outlined. Xcode does not stop execution at these breakpoints although code has been compiled, loaded and executed. I checked it in Console by adding some prints.
When I hover over breakpoint Xcode shows a message:
Xcode won't pause at this breakpoint because it has not been resolved
Resolving it requires that:
The line at the breakpoint is compiled.
The compiler generates debug information that is not stripped out (check the Build Settings).
The library for the breakpoint is loaded.
All trivial solutions like reloading, reapplying breakpoints have not helped.
Did anybody else see something like this? Is there a way to solve it?
Screenshot for reference:
Ok, so in my particular case rebooting laptop has helped. All breakpoints are now good. But it would still be nice to know the cause of the problem.
Make sure that the file in which you are adding breakpoint is having correct target set in target membership.
Click on .m file in which you want to add breakpoint.
Select the file inspector.
Check if you have selected correct target for that file or not (check below image).
What worked for me, was to select the files, delete them with - Delete>Move To Trash - and then drag the files back from the trash to the project.
In my case the issue was happening, because class was not added to the target, which I was trying to build.
For my case somehow the code path was never invoked and very likely considered as dead code. The same thing applies when not adding the file to the target that you want to debug.
This can be the case or somehow debugger might not be able to resolve your breakpoint. The first thing in this case should be cleaning derived data and any caches.
But instead of recloning your repo you can just delete breakpoint config from the location described in this answer
In Xcode 14 the problem is much more prevalent and "consistent". I figured out one pattern where it always fails and how to mitigate it.
If you have a final class then breakpoints set on or inside a private method will have that issue. If you remove private from the method or final from the class the breakpoints will get resolved properly.
If tried everything and nothing worked I suggest the following:
Reclone your repo
This is what worked for me.
I just passed through this problem and the solution for me was recreating the files.
Note: The ones I was trying to originally breakpoint on were copied from another project. When I created the new files, even though their Identity and Type looked just the same (target membership, encoding, paths), for some reason breakpoints started to work again.
Note 2: When copying and pasting code to your new files (if done manually), migrated breakpoints - created in the older file - will continue to fail. Only the ones created in this new file will work properly.
Hope it helps.
My case
Working on framework development. Framework is injected into the sample app for development/run purpose. Breakpoints inside the framework won't work.
Fix
Just removing xcframework in sample app and replacing with framework.
Reason
xcframework are precompiled outside of the app, so lib isn't compiled when project is built and that's why breakpoints doesn't work.
For me reboot the Xcode, and it works~

Eclipse won't compile SWT file properly after SFTP transfer

I was coding earlier today using Textastic 9 on my iPhone today using files I had downloaded over SFTP. I sent them back to my computer (the whole project transferred to my phone), and now three of the four work. They compile correctly, and the colour coding works perfectly. The last one, however, only colour codes specific keywords and strings. It won't accept variable names and anything from a separate library/file, say org.eclipse.swt.SWT.
Here's a screenshot of that file:
Here's another file that also went through SFTP that's working perfectly:
I'm also getting the error Syntax error on tokens, SimpleName expected on a return; statement. I've also tried pasting the code in Notepad, deleting the file, and pasting it into a new file. That doesn't work.
Thanks to #Ros5292
It turns out the display() method had parameters with incorrect capitalisation. I fixed this, clicked on the Design tab, selected the root method, and it compiles. It still doesn't allow me to use other files, color code, etc.
Thanks to #Ros5292
It turns out the display() method had parameters with incorrect capitalisation. I fixed this, clicked on the Design tab, selected the root method, and it works. The colour coding and stuff were messed up due to a few errors because the file was technically new, and it hadn't compiled properly for the first time ever.

NSXMLParser gives EXC_BAD_ACCESS only with ARC enabled

Well, the subject pretty much says it all. I have code to unzip and parse an epub. It works fine if I don't use ARC, but I get a EXC_BAD_ACCESS if I use the same code (without the retains and deallocs of course) with ARC enabled.
The code bombs during the parse method of the NSXML parser.
The code I am running is: http://ideveloperworld.blogspot.in/2011/02/epub-reader.html
You might be thinking, why not just proceed without ARC then, but I am integrating the epub reader into a much larger project that already uses ARC.
Thanks for any help.
If you want some files to be compiled without arc, here's what you need to do.
go to your project (click on the blue folder in the Project Navigator), then go to build phases. Click Compile Sources, which should be a list of files in your project.
For any files that you want to be compiled WITHOUT ARC, Set a Compiler Flag for that file to be: "-fno-objc-arc". It should look like this:

Upgraded to IOS5 - App Won't Build

I've upgraded my IOS4.3 app to IOS5 and am getting compile errors. From what I can tell, the syntax looks fine, but the compiler is complaining of "Unexpected #" when I synthesize properties, but only in some classes.
I also have an "Undeclared identifier" in one ViewController's viewDidLoad method.
I've performed a clean build and I'm guessing that there's a default setting which has been changed somewhere, but from scouring around this doesn't seem to be a common issue. Is there a list of common breaking changes anywhere?
EDIT:
This screenshot is one of my ViewControllers, which is derived from UITableViewController
There is a missing # in the line self.title = NSLocalizedString(...). The second parameter doesn't have the leading #.
Coming from a .NET/PHP background, I have very little experience with compilers. The problem was that Apple seem to have changes the default compiler for IOS5 from GCC to LLVM, hence the difference in syntax. It would be nice to be able to use the newer compiler, but GCC's the only one which gets anywhere near close.

Does Xcode Always Compile from Scratch

I sometimes see that change I made shows up on third or 4th build run. It's as if xcode "cache" old compilation.
How to delete all compiled file and start from scratch
One thing that's particularly frustating is this:
I got a compile warning
for this code:
[self.currentBusiness addCategoriesObject:self.currentCategory];
I know what the problem. The automatically generated core data code do not have
- (void)addDistrictsObject:(District *)value;
- (void)addCategoriesObject:(Category *)value;
on Business.h. The function is defined in Business.m though.
So I added those 2 lines. Guess what, still the same warning. I had this exact same problem several time with no issue. I know the solution. I put the line right there in business.h. Nothing changes.
Yet now I get the same compiler warning even though the method is CLEARLY defined in business.h.
As if xcode do not care about the last change I put.
I am so frustated. I added #import "Business.h" again in my utilities.h. Shouldn't change anything given that "Business.h" is already included through other channel. Guess what, it works.
But then I thought, ah that's the problem. I curiously remove that //#import "Business.h" again so it's back like usual. If that's really the issue then the error should show up again right? Wrong.
The error is gone.
So changes I made do not show results right away. Either the compiler or the precompiler must use some sort of cache.
This is important. There are bugs that are introduced 2-3 builds before that I don't know how to debug. If code changes right after the first build after I make that change I know that something is wrong.
Also that autorestore doesn't seem to work. I create a snapshot, restore the snapshot into another directory and get lots of compile error.
NO, It only compile the file in which any kind of any editing took place.
Xcode does incremental builds. You can do a clean build by going to the Product menu item and select Clean (or press Shift+Cmd+K). That will delete all intermediate files and start from scratch.
Click xcode -> Empty Caches.
Here is a screenshot.