In Xcode 4, setting User Header Search path breaks code sense - xcode

My desired setup is a main project, which depends on a subproject (which generates a static library). Adding the subproject to Xcode works fine, but as you'd expect you have to set the User Header Search path to include the subproject's folder, unless you want to add the subproject's files to the main project explicitly, which sort of defeats the purpose of the subproject.
From what I can tell, setting the User Header Search path will break code sense and "jump to definition" navigation in the main project, next time your open the project.
Here's a sample, super simple, stock project that illustrates the problem:
http://dl.dropbox.com/u/579169/MainProject.zip
If you go to the Application Delegate and try to jump to definition on a property reference, say self.window, Xcode simply gives you a list of all the "window" properties it knows about. Likewise, autocomplete fails to work.
If you delete the user header search path, close the project and reopen it, code sense works as expected.
I've filed a bug with Apple, but was wondering if anyone has run into this specific problem, or has a reasonable workaround. Deleting the project "derived" build folder to trigger a reindex doesn't work reliably.

A work around is to make the headers public in the static library. Then add the following to user header search paths
"${BUILT_PRODUCTS_DIR}/usr/local/include/"

I reported this to Apple, and they report that it was fixed 6/6/2011 in XCode 4.1 (which is Lion only). I have not confirmed the fix as I have not upgraded my development machine to Lion beta.

Related

XCode Unknown class ***** in Interface Builder file

In an app, suddenly it's giving me the error XCode Unknown class ***** in Interface Builder file. I reviewed everything, storyboard, classes, etc.
I try to rename the class but it is the same problem, even I created a new class and copy the code in. I think XCode is taken that from a kind of cache because even properties that I deleted like the icon in the tab bar item are still present in the app when I run it.
What can be the problem?
Also if using a static library, don't forget to add the -ObjC flag to Other Linker Flags in your projects Build Settings tab.
If you have failed to do so, "Unknown class ... in Interface Builder file" will occur when trying to load a view controller from the static library in IB.
Just another case I experienced the error will show.
I faced a problem when I created a project with the same name that already existed in my projects directory (though it was deleted some time ago). Xcode didn't understood that it's a new project and use build directory of old project as a build directory for a new one. I didn't knew how to completely rebuild project from scratch and I just removed a build directory.
In my case I removed /Users/username/Library/Developer/Xcode/DerivedData/ProjectName-suffix. You can find it in Xcode in Project navigator on the left by selecting ProjectName->Products->ProjectName.app and File inspector on the right will show you a full path to file.
Sorry, after trying several post I found one solution, delete the folder of the simulator in /...Library/Application\ Support/iPhone\ Simulator/ and removing the class and re-adding it.
You will need to add to your targets Other Linker Flags as well, just adding to the Project Build Settings does not seem to work.

Xcode referencing old/removed frameworks, causing multiple interface declarations

I'm getting interface re-declaration errors when I'm trying to build because xcode keeps referencing these old frameworks and headers that I've already removed from the project. I've sifted through my build phases and build settings and nothing seems to point to those files.
The funny thing is when xcode shows me my error and the line of code where the interface is supposedly redeclared, it won't show me any specific file when I click "Show in project navigator". However, if I ask it to "Show in finder", it instantly locates the file in my actual project directory (not xcode project directory). So this means that XCode is picking up unwanted frameworks that I've left in my project directory. I don't want XCode to do this. How do I clean this up? I've tried cleaning, restarting xcode and rebooting.
I looked at another SO discussion with the same problem but the user didn't give a proper solution (http://stackoverflow.com/questions/11759444/xcode-referencing-old-framework). How does one go about disabling the automatic framework searching?
Just in case: have u checked FRAMEWORK_SEARCH_PATHS ? (Project Build Settings). I had a similar situation and found there references to the old paths which I removed and that did the trick.
ADDITION:
As I moved my Xcode-Project to another location the compiler complained about "Library Search Paths" which where pointing to the old location.
See => Build Settings, "Library Search Paths".

Unexpected errors when building for profile in XCode 4.5

I have a project that I refactored for iOS 5 and ARC. It builds and runs fine, Analyzer finds nothing and I'm on the brink of submitting it to the App store. Before doing that, I thought it would be a good idea to check for leaks, just in case I missed something during the arcification. However when I choose "Product -> Profile" from the XCode 4.5 menu I get a flood of warnings and errors. All of them indicate that the build for profiling is not recognizing that the project is using ARC. The scheme settings for profile are set to use the same arguments and environment variables as run, but run works and profile doesn't. If I choose the "Profile without building" action, everything works. I've checked to make sure that there is only one version of XCode installed, checked the path, and it's all good. This is not a show stopper, but I'd like to know what's happening, and what setting to tweak if that's all it is.
Problem solved by deleting project.xcworkspace and xcuserdata folder from the project bundle. Apparently they got corrupted somewhere along the line.

Generic archive created when updating an existing Mac app?

I've made an update to my existing Mac app and went to archive it.
In Organizer it came up as a new entry and not under the previous releases I had. This new entry appears generic, ie. no app icon, no version or identifier info, just the name of the app came through. What happened? How do I troubleshoot?
In the update I added a UTI and also copied a plug-in into my bundle. Could those things have something to do with it?
Got it. My problem was related to dependency targets. Here's the solution:
http://www.weston-fl.com/blog/?p=2429
(Excerpt added 2012-12-18; see blog post for screenshots and background info)
… Select dependent project(s) in the Project Navigator
Find “Skip Install” and set to YES.
If you have more dependent project, repeat these steps for all of them (i.e. at static library projects).
The app is expected to be deployed so do not change the Skip Install’s No to YES there. Change at the dependent projects only.

Xcode 4 code sense is not working

I am running a "old" Xcode 3 project in Xcode 4 and code sense is not working for my own classes. I have tried following:
Clean/rebuild
Remove Derived Data
Installing 4.3 documentation
Restart
Without any luck.
Sometimes the code sense works but mostly I just get "No Completions".
Try this:
Open Organizer then Project Tab.
Clear the "Derived Data". Xcode should re-index your project then and code sense should work. At least worked for me.
I know this is late, but for reference: http://sealedabstract.com/code/when-xcode-4s-code-completion-autocomplete-breaks/
Close the project, leaving XCode still running.
Open XCode’s Organizer window, go to the Projects Tab, select the correct project, and hit the Delete button next to “Derived Data”.
Quit XCode.
Navigate to your project’s .xcodeproject file in Finder. Right-click, choose “Show Package Contents.”
Leave the project.pbxproj file, but delete the project.xcworkspace file, any .pbxuser files, and the entire userdata folder.
Open the project in XCode. You will see XCode riding high on the CPU usage for around 10-60 seconds, depending on the size of your project. The activity window will say “Indexing”
When your CPU spike returns to earth, code completion will be working again.
There's a lot of deleting going on there so please be careful, but this definitely worked for me.
I've been doing this, and it's worked multiple times for me (after trying all of the above previously).
Edit: Now I just hit space, backspace (the mac version) and rebuild... works nice. Then, remember to scroll (sometimes the colors don't show up until you scroll somewhere)
Find your prefix file: "ProjectName_prefix.pch".
Comment out some line. (basically change it)
Build your project, doesn't matter if it fails or not.
Uncomment it.
Build again.
I'm betting only step 2 (modify the prefix) is what does it, but these essentially get you back to running. Suddenly everything magically recolors itself and completes functions.
Good luck if that doesn't fix it, perhaps try doing this to your dependency pch files (three20 or FB api's)
Clearing the "Derived Data" only works temporarily for me. I have to do it and then restart Xcode like 3-4 times each day to get code sense working again.
I found out the real cause is in the Target's Build Settings. I moved everything from Header Search Paths to User Header Search Paths and it is fixed. In my case, the framework I'm working with is RestKit.
BTW, I came up with this because I was adding another project (QuickDialog) into my project and I was curious that it is using User Header Search Paths, but not Header Search Paths. Here is the difference between them.
You can able to fix that issue by change build settings like this, PreCompile Prefix Headers :NO
FYI, if one file doesn't have code sense but the rest of your project does, check that its added to a target. Once I did that I got code sense back in that file.
It's been ages but the answer is just to move the code into a new folder and the code sense should be working now.
This happened when I added a new Objective-C Class and the code sense doesn't work only on the newly added .m and .h files (on XCode 4 latest update during this post).
Close all xcode windows
Delete all your projects from xcode>window>organizer and restart your project. It will now sense and index your project properly.
I wrote about it in detail here.
Basically my fix was that with localization. I upgraded from xcode 3.2.5 to xcode 4 and then screwed around with built in interface builder and turned on localization for a XIB file accidently which placed my source files in en.lproj directory. After moving them back to Classes folder it worked perfectly.
Again, for the sake of helping others with this issue which, in my case, happened upon upgrading to Xcode 4.3.
Of course I tried the solutions offered in this post, and none of them worked. But the suggestion to move the location of the project in Finder brought back some Code Sense, but the suggestions didn't make any sense.
I ended up deleting my project and re-cloned it from the git repository.That brougt back Code Sense for me...
I open a second project in the background whenever my Xcode's code sensing stops working (it usually works the first time i open the project but after a while code sense no longer works). So what i do is to open a second project in Xcode. Xcode will start indexing the second project and magically the code sense for my main project is back.
Running Xcode 4.3.1 on Lion
Hope this helps someone.
From this comment here I was able to debug the problem on my end, it seemed to be a bad -w flag that the clang preprocessor wasn't recognizing properly. Basically, running
defaults write com.apple.dt.Xcode IDEIndexingClangInvocationLogLevel 3
in Terminal increases the verbosity of the indexer, and should help you track down issues. Open Console.app and look for messages from Xcode, the search string IDEIndexingClangInvocation helped me find them.
For me it happened simply because the file had no target membership. If the first few answers did not work for you, go to your .m file (presumably it's this file that you're having trouble with), open the Utilities view (Edit -> Utilities -> Show File Inspector) and under "Target Membership" check the target to which you want this file to belong.

Resources