Why does 'clean' magically fix mysterious bugs in my app? - xcode

If I ever have a problem that is not showing up as a warning, but makes my app crash on runtime, sometimes I'll build->clean and often it this unkown bug disappears. This happens mostly when I import new images into the project(replacing old ones) or when I make major syntax changes with my code.
F'in 'Clean all Targets', how does it work?
Thanks

When you build for the first time, all of your code is turned into object code. That way when you make a tiny change to one file, you don't have to recompile your whole project, just that one file.
Now sometimes things go funny and stuff doesn't align properly, or dependencies aren't updated and boom crash. The build system is supposed to detect this but every project I've worked on has had this problem at one time or another.
Build clean deletes all the intermediate object code and recompile from scratch.

When you clean your project, you force your entire application to recompile itself. Maybe one of your resources was compiled into your application in a way that required you to recompile everything when changing the resources?
What sort of application are you building - do you use threads? I would make sure they aren't race conditions, because their trademark symptoms are sporadic non-reproducible errors.

Related

Need to always reload project in Xcode for it to function

I've built a couple dozen projects in Xcode and only one of them experiences this strange issue.
Every time I load Xcode to resume work on the project, Xcode auto-loads the project (good) but in an unusable state (bad). It appears this way:
The project name is grayed out, with no disclosure triangle. I cannot access any of its contents, and trying to build it fails immediately with no error message other than "Build Word Practice: Failed" as you see in the screenshot.
But if I close the project and reload it, it functions fine. The only oddity about when it loads this way is that it appears with all its disclosure triangles closed, and I have to manually "disclose" the contents of all the folders in the list each time:
I have had this issue with all recent versions of Xcode, up to and including the current version, 11.5.
The project does not use any features that are not present in other similar projects I've written that behave fine. So it would seem to be a matter of corruption… but besides deleting derived data and doing a clean build (which I've done), I can't think of any other steps to take.
I would include code here, but short of including the whole project (and I doubt that would help), I wouldn't know what to include.
Any ideas?

Xcode4 breakpoints adapt to code changes?

I have a series of logging breakpoints in Xcode4 that I'm using to selectively log things as I need them. However, whenever I make changes to the code involving adding or deleting lines, these breakpoints get out of sync with where they are supposed to be, sometimes even going to a completely different function.
Is there a way to keep the breakpoint in sync with the code, rather than just rely on the line number?
I believe it should, at least it's the IDE's usual behaviour.
Just a thought. Have you tried to reinstall XCode? I have experienced all sorts of weird bugs since the upgrade to XCode 4. For example, being unable to select a XIB file for a popup window in a project---and when creating a project from scratch, I was able to select that XIB and create the popup. At the time I posted a question on StackOverflow about this and it is still unanswered ever since.
Since that time, the project was overhauled and now I build my interfaces from scratch using full Obj-C code, dumping the interface builder 99% of the time...

Certain functions/methods not changing when built in Xcode

I am currently working on a project which runs just fine in both the simulator and on device except for one particular method which does not update on the device or in the simulator. It seams that I can put whatever I like in it and it just runs an old version. If I change other methods in the same file they build and run with the changes. Any ideas why this is happening or what I could do to solve it?
One suggestion I heard was to start a new project and copy my code in. I would like to avoid that if possible but it looks like I might have to.
Sometimes you need to do a clean build because Xcode does not always notice dependency changes (e.g. changes to source files).
Some people do not configure their dependencies (e.g. static/dynamic libraries) correctly. If you are using the auto-detect-dependency feature, it still has some bugs, so you may need to configure this explicitly.
FWIW, starting a new project has never been necessary for me...

When and why should I clean the build in XCode

Every once in awhile, the solution to an aggravating problem in XCode is to hit Product → Clean, and this seems to clear some cache and problems disappear.
But what is it actually doing? And more importantly, WHEN should I be doing this? It seems to be necessary more often when dealing with Core Data, but I haven't really been tracking it.
As a side question, WHY is this necessary? XCode seems to do a lot of stuff in the background (autosave, autocompile, etc). Why doesn't this also just happen in the background?
It's because there are a lot difference when you are working with a very very big project with a lot of files and objects. Imagine that you need an hour to recompile a entire project, so you will think before do this. But in our world, this is a fast task.
XCode use the make program. So, it compile only what was changed.
I can list same cases you need do this:
Always you will create a App for App Store. This safety thing to do.
Always you use the XCode Snapshot. I have bad time when I restore a project and build the app. XCode used old compiled files and a lot of time was lost to search it.
Maybe when you restore a old code with git. Is the same idea of the Snapshot
When you delete or rename a file in project. It don't delete the compiled file, so the program can work, but if you recompile, will see the errors.
When you see that sometime the build have a strange behavior. Or only to have certain that XCode use only your newer files.
I don't remember exactly but i have seen the build use old #defines. Rebuilding can make you more safe about your program. But don't need do this all time.
I am almost certain that XCode loses track of things and sometimes it doesn't recompile (or link, not sure) everything is needed. I have to resort to clean and build all most often than it should. Maybe it's just me, but I doubt it... XCode is the IDE with most bugs I have worked with

Why is xcode(4) so slow to dismiss errors I've already fixed?

So I hit Cmd+B and xcode throws all these errors and warnings at me. But after I fix them, xcode is sometimes slow to catch on, often requiring another Cmd+B on my part to nudge it to recheck the file. Is there a setting somewhere I can toggle to make xcode recheck for errors more aggressively?
It seems there's still room for improvement on the things that cause Xcode to retry your code. One thing I've noticed is that if you change something in a header than navigate back to the implementation, it quite often won't detect the fix until you force a build (or run it, which builds first).
The workaround? Save (Cmd-S) the file before navigating away from it or save all files (Cmd-Opt-S) if you've fixed several problems across several files.
The long-term solution? File bug reports at http://bugreporter.apple.com

Resources