XCode 4 Autocomplete with C++ library? - objective-c

I am using Cocos2D Box2D template for my project.
When I type , "b2**" the autocomplete doesnt show any Box2D classes. (pressing ESC also doesnt show any )
I have included Box2D.h and Cocos2d.h in "Prefix.pch" file.
Is there any feature like "rebuild index" in "Eclipse CDT" ?
Any tips?

You can force Xcode to rebuild index by deleting it's service folder (DerivedData for Xcode 4.x):
Close Xcode
Remove service folder
Open your project and Xcode will rebuild index again
In my case this always works and I can call b2... autosuggest.
The DerivedData folder can be found in ~/Library/Developer/Xcode/DerivedData

This may be an obvious suggestion, but have you tried to type out a class that you know exists with what you have included, and see if it recognizes it(With both colorization and/or quick help)? Also, do you have the necessary frameworks included, etc? As far as reloading goes, the only thing that you can do in XCode that I know of is clean(shift+cmd+k) and re-build. Are you getting any sort of warnings, errors, etc? Another potentially obvious issue, is XCode set to c++ as the language? Anyways hopefully you haven't already tried all of this and it helps you get somewhere.

Assuming you're using XCode 4, you can rebuild the index rather simply:
Open the Organizer (Command+Shift+2)
Click 'Projects' in the top section
Select the project you want to rebuild the index for in the left sidebar
Click 'Delete' next to 'Derived Data' in the center portion of the Organizer
This is easier than traversing through the directories and manually deleting a series of folders.

This page lists the steps another user went through to get code completion working for Xcode 4 and Box2D – the steps include deleting the derived data folder, but also changing user header search paths, making sure there were no spaces in the path to the project, and other things. Some of these steps may be random or unrelated, but apparently they fixed the problem for two people on that forum.

Combining all the above posts together, this is how I went about solving my issue:
1) Make sure that all files are in 1 folder. This may sound obvious, but I had my Box2D files not in the same folder as my other code. When creating a new project with XCode, it creates a folder with the name of your project, then another folder within that that has the name of the project again. Example: "{path of project}/TempProject/TempProject". I had my Box2D files in the first TempProject directory and not with the rest of my code that is created under the sub-directory of TempProject.
2) Open your project's settings by double clicking your project in XCode
3) Scroll down to "Search Paths"
4) Edit the "Header Search Paths" value to be: ${SOURCE_ROOT}/${PROJECT_NAME}/** (Note: If your Xcode does NOT create a subdirectory like mine does "TempProject/TempProject", then just use ${SOURCE_ROOT}/**)
5) Delete your project's Derived Data by doing 1 of the 2 following ways:
a) Open Organizer -> Select Projects -> Select your Project -> Select Delete next to Project's Derived Data
b) Open Finder -> Select Go from the toolbar -> type in "~/Library/Developer/XCode/DerivedData" -> Find and Delete desired project's folder
6) Restart Xcode
7) Clean and rebuild code
8) Code sense should now work!

Related

Xcode 6 Swift code completion not working

Using Xcode 6 GM seed my code completion has stopped working. It was working the other day. I was trying to get the unwind segue work around to work. I had made an Objc header file and assigned it as a header for a Swift class.
At this point I get code completion with an Objective-c project. But, not with a Swift project.
I have tried restarting Xcode, making a new empty project.
Just go in user->Library->Developer->Xcode->DerivedData and delete the Data of folder(Derived data) and restart Xcode.
This fix from apple dev forums works for me. I have had autocomplete issues with Xcode 6.1/Yosemite.
Quit Xcode.
Restart the computer (this is to clear any in-memory caches).
Delete the contents of the DerivedData folder (~/Library/Developer/Xcode/DerivedData), precisely run, a) cd ~/Library/Developer/Xcode/DerivedData/
b) rm -rf *
(Try this if Steps 1-3 dont really work as it rebuilds the cache later on restart which takes time) Delete the contents of folder ~/Library/Caches/com.apple.dt.Xcode, i.e., a) cd ~/Library/Caches/com.apple.dt.Xcode b) rm -rf *
Now launch Xcode once more…
I experienced a serious breakdown of code completion because I had some 'notes' after the #end statement of my .m file which were as follows:
/*
NSAlertFirstButtonReturn, NSAlertSecondButtonReturn, NSAlertThirdButtonReturn
*/
These lines can appear before the #end statement without destroying code completion.
There's an easier way to delete the Derived Data from within Xcode (no need to open finder or restart):
Xcode Organizer -> Projects -> (Your Project) -> Delete Derived Data
I just recently had this problem. Autocomplete did not work ...and when i typed for example tableView.... it did not give me the different functions available.
I tried the following and it worked for me.
Xcode Organizer -> Projects -> (Your Project) -> Delete Derived Data
delete the file ~/Library/Developer/Xcode/DerivedData/ModuleCache
Restart xcode
Hope this works
Another possible reason why it isn't working is because it's not part of the target membership. To fix this, select the file you're working on. Then, go to the File Inspector and in the Target Membership section, make sure your project is checked.
Try the following - as silly as it may sound:
Change Device to iPhone 6, close Xcode, Reopen Xcode and wait for the indexing to finish.
Go to Xcode menu, then Window -> Organizer, then select Projects. Pick your project and press on delete button beside dervied data
Then restart Xcode
That solution worked with me on Xcode 6.1
If your code completion problem is only with UI classes (e.g. UIImage, UIDevice), then you just need to add "import UIKit".
Swift files will NOT have code completion for UI classes unless there is an "import UIKit".
I had the same issue but under different circumstances,
I have 2 projects in my workspace
Swift framework for iOS and OSX
iOS Project (which uses the swift framework)
My code completion works fine in iOS but it keeps failing in the swift framework. I tried all the about solution and had no luck and was killing my productivity.
Finally i figured out the solution to this problem.
Select the file you are editing (in the framework )
Select the 'utilities' tab on the right
uncheck the Mac target (just keep the target you are working for
currently)
Thats it, this solved my problem.
hope it helps someone who is in this kinda situation.
user/Library/Developer/Xcode/DerivedData Delete all the files shown in this folder. after that go to your project name and clean project then come back to the file where you wanna see suggestions. Type any word and its done.
So all you have to do is make sure, in the file inspector view on the right side, under Target Membership, the first box is checked. I'm not sure why this changes things but I'm sure someone can come along and give a more complete answer.
In my case Some File(s) were deleted in File System but were still referenced in the Project i.e. in Red Color. Just delete those from Project and everything was fine. Code Completion started working.
Also Like to point that all the above answers about Clearing/Deleting Derived Data folder seems to work momentarily but whenever there was a new pull or update the problem started again, so the root cause was the unreferenced/moved/deleted files which show up as RED in the project, they needs to be manually cleared.

How to delete projects in IntelliJ 12?

I created some dummy projects. Now I don't see any way to delete the projects that I don't want. Per this suggestion I can delete files, the project is going away but there is traces of it still available. For example, on the Recent Projects you can still see the name of the project you just deleted. So I am thinking there should be another (and really easy way) to delete a project.
Press the Del (or fn and delete) key to delete a project from the Recent Projects list.
Vote for this issue to make it more obvious and user friendly.
close project first, or until this dialog appear, then hover your mouse on project you want to delete from history, then press Del
you'll be asked for confirmation
On occasion, even with deletion of the project, some tidbits are left behind in the following Windows paths:
C:\Users\username.domain\.IntelliJIdea2017.1\system\compiler
C:\Users\username.domain\.IntelliJIdea2017.1\system\compile-server
C:\Users\username.domain\.IntelliJIdea2017.1\system\frameworks\detection
C:\Users\username.domain\.IntelliJIdea2017.1\system\conversion
C:\Users\username.domain\.IntelliJIdea2017.1\config\componentVersions
C:\Users\username.domain\.IntelliJIdea2017.1\config\tasks
This has been proven to be problematic - for example, if a new project is created using a previously deleted project name, it will create the project with data stored in the above paths, at least, this has been my experience.
The only way to TRULY delete the project is to get rid of all the garbage left behind in the aforementioned folders. I would suggest using Search Everything to find more tidbits left in the users temp folders.
In case your project is imported as a module, you can also go to File --> Project Structure and click 'Modules' in the left section. Now you can hit the minus button to remote the module from the project.
You can also click File -> Open project ...
When a file menu appears, you can right click the unwanted project folder and select Delete.
Just figured, I am using Idea Community edition 13.1.1 and the cleanest and easiest way is to go to File > Reopen project > Clear List. I just stumbled upon this menu today. I always thought that is just to clear the latest projects from the view inside the IDE and just realized it is clearing the projects from the main Dialog too.
-VRS
Also, in IDEA 13.x.x you can go File-> Close Project and you'll land in the window with Recent Projects tab. There pressing Del of Fn + Del on selected project helps .
On OSX Mountain Lion and IDEA 14, with the project open and focused, you can go to file -> close project, then delete the project from your filesystem. This removed all references to the project.
Note that if the project you are deleting is the only project open, closing it will show the welcome dialog, which will still show the project. Deleting the project manually from within your operating system is the next step, and the project will still appear in the welcome dialog until it is closed and shown again, usually by opening another project from the list, or quitting and restarting IDEA.
In my case, I had to delete home/.IntelliJIdea2017.2/config/options/recentProjects.xml
. In my file system (Ubuntu) this file appeared for some weird reason not writable and hold a list of projects I couldn't get rid of. Deleting this file and restarting will force Intellij IDEA to create a new one with an empty list of projects.
All you have to do is go to file - close project - to avoid seeing them again in the menu list and then you delete them from the projects directory.

Is there ANY way to make Xcode monitor folders for files adding / deletions?

I'm using Xcode for a year now, and it's always bothered me if there is any way to tell Xcode to actually "Include the folder" in the project.
What I mean by that, is that I want that when I create or drop new file inside that folder, Xcode will automatically add it to the project.
Of course it should be the same about deleting - I don't want Xcode to complain all the time
OMG I can't see file! I'm gonna cry and make it shiny red.
Rather I want Xcode to just remove the file's reference from the project.
So, Is there any way to do that?
Thanks!
No.
The closest thing you can do is drag your folders into Xcode from Finder. For deletions, delete in Xcode first and select the button for moving your files to the trash.

Xcode 4 code loses syntax coloring when importing project from Xcode 3

I have just upgraded to the new Xcode 4 and the code is not colored has it should be.
I am trying to use a project that I created on Xcode 3.
For instance, the string 'NSString' is not colored in my custom code, but when I switch to Apple's code (NSString.h for ex.) everything is well colored.
How can I fix that?
Thanks a lot,
Martin
Open the Organizer (Window > Organizer) and select the Projects mode. Select your project in the left-hand view and then click the Delete… button for the project's Derived Data.
This will delete the code sense index for the project and force Xcode to rebuild the index, which should fix the problem.
I got it to work by prefixing all my project search paths with "$(SOURCE_ROOT)/" instead of just using a project relative path. Eg "Include" becomes "$(SOURCE_ROOT)/Include".
Do this and then force a rebuild of the index by deleting the projects derived data from the organizer.
After trying most, if not all, of the steps above, I have succeeded in restoring my colorful Xcode eye candy by finding and deleting (in Finder) all of the derived data created from my project (there were several folders for my project that were lingering even after deletion from the Window > Organizer menu).
My project's folders that needed deletion were located in ~Library/Developer/Xcode/DerivedData
Also try this, select all(command + A) from your Prefix.pch file -> cut it(command + X) -> Build(command + B)(don't worry for error) -> paste(whatever you copy from Prefic.pch file in that file only)(commmand + V) -> Build again (command + B).
Try Product -> Clean and then Product -> Build
Remove the files from your project (just remove, don't delete them!) and re-import them.
Its possible that the permissions on the folder where Xcode stores the code-sense cache is broken. If the cache cannot be correctly written or read when you launch Xcode, it will behave as you describe.
Try locating the folder (you can locate it in the organizer. Hit the arrow next to the path.) and reset its permissions in the Get Info dialog.
There is another cause for this issue, it had been happening to me with beta versions of Xcode, you need to check that the .m file is added to the target in order to make it add color to the classes and enable the autocompletion.
You can check it out in the Xcode inspector
Hope this helps,
best regards,
Jorge.

libxml/tree.h no such file or directory

I am getting following errors.
libxml/tree.h no such file or directory
I have already added libxml2.dylib to my project, however I am getting this type of trouble.
Please help me.
Follow the directions here, under "Setting up your project file."
Setting up your project file
You need to add libxml2.dylib to your project (don't put it in the Frameworks section). On the Mac,
you'll find it at /usr/lib/libxml2.dylib and for the iPhone, you'll
want the
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.0.sdk/usr/lib/libxml2.dylib
version.
Since libxml2 is a .dylib (not a nice friendly .framework) we still
have one more thing to do. Go to the Project build settings
(Project->Edit Project Settings->Build) and find the "Search Paths".
In "Header Search Paths" add the following path:
$(SDKROOT)/usr/include/libxml2
Also see the OP's answer.
Adding libxml2 in Xcode 4.3 / 5 / 6
Adding libxml2 is a big, fat, finicky pain in the ass. If you're going to do it, do it before you get too far in building your project.
You need to add it in two ways:
1. Target settings
Click on your target (not your project) and select Build Phases.
Click on the reveal triangle titled Link Binary With Libraries. Click on the + to add a library.
Scroll to the bottom of the list and select libxml2.dylib. That adds the libxml2 library to your project.
2. Project settings
Now you have to tell your project where to look for it three more times.
Select the Build Settings tab.
Scroll down to the Linking section.
Under your projects columns double click on the Other Linker Flags row.
Click the + and add -lxml2 to the list.
Still more.
In the same tab, scroll down to the Search Paths section.
Under your projects column in the Framework Search Paths row add /usr/lib/libxml2.dylib.
In the Header Search Paths and the User Header Search Paths row add $(SDKROOT)/usr/include/libxml2.
In those last two cases make sure that path is entered in Debug and Release.
3. Clean
Under the Product Menu select Clean.
Then, if I were you (and lets face it, I probably am) I'd quit Xcode and walk away. When you come back and launch you should be good to go.
For Xcode 6, I had to do the following:
1) add the "libxml2.dylib" library to my project's TARGET (Build Phases -> Link Binary With Libraries)
2) add "$(SDKROOT)/usr/include/libxml2" to the Header Search Paths on the TARGET (Build Settings -> Header Search Paths)
After this, the target should build successfully.
You also need to add /usr/include/libxml2 to your include path.
Form the link of #Matt Ball,
I found following helpful to me.
You need to add libxml2.dylib to your project (don't put it in the Frameworks section). On the Mac, you'll find it at /usr/lib/libxml2.dylib and for the iPhone, you'll want the /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr/lib/libxml2.dylib version.
Since libxml2 is a .dylib (not a nice friendly .framework) we still have one more thing to do. Go to the Project build settings (Project->Edit Project Settings->Build) and find the "Search Paths". In "Header Search Paths" add the following path on the Mac:
/usr/include/libxml2
Ray Wenderlich has a blog post about using gdata that solves this problem. Basically these simple steps:
In XCode, click Project\Edit Project Settings and make sure “All Configurations” are checked.
Find the Search Paths\Header Search Paths setting and add /usr/include/libxml2 to the list.
Finally, find the Linking\Other Linker Flags section and add -lxml2 to the list.
original post: read and write xml documents with gdataxml
I found the same, I had to add $(SDKROOT)/usr/include/libxml2 for the latest Xcode (4.3.x). ALSO, what kept me circling around for hours is the fact that I was modifying the "TARGET" and not the "PROJECT" (the new UI of Xcode is so intricate that its easy to overlook this). You need to modify the PROJECT!
Another solution. do all the steps in header search path etc. and make sure your selected configuration in project in Project settings is the correct one. When you double click on project build settings ,you may be changing in Distribution settings, But you are trying to add header search path in "Debug" settings. So make sure you are in correct settings. or choose all settings
I found that with xCode 4.3.2 I had to enter
$(SDKROOT)/usr/include/libxml2
into the Header Search field rather than simply
/usr/include/libxml2
As of Mavericks (OS X 10.9) the /usr/include directory is gone. Half of the answers here are obsolete, as the application will not compile until you sort out the include directory.
I solved the problem creating a symbolic link to MacOSX SDK in terminal, using the following command:
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include /usr/include
The application now compiles again.
I'm not sure what the difference is but add the include path to the project as well as the target.
On Mountain Lion I was facing same issue, which was resolved by adding /usr/include/libxml2 to include paths with flag "recursive", use this if all above is not fruitful.
I had this problem when I reopened a project (which was developed on XCode 3.something on Leopard) after upgrading to Snow Leopard and XCode 3.2. Curious enough, it only affected some kinds of builds (emulator builds went fine, device ones gave me the error). And I have libxml2 at /usr/include, and it indeed contains libxml/tree.h.
Even the magic "Clean" did not work, but "Empty Caches..." under the "XCode" menu (between the Apple logo and File) did the trick (was that menu there in previous versions?). Beats me the reason, but after a clean there were no more complaints regarding libxml/tree.h
Also select "Always Search User Paths" to YES. In XCode 4.3.3 its by default NO
Please follow the following steps
Adding libxml2
libxml2.dylib can be found on your mac machin at /usr/lib/libxml2.dylib
Change "Header Search Paths"
Click on [Project Name] (in left panel) -> Project -> Build Settings -> Select All (default is Basic)
Type Header Search Paths in search box
Double click on Header Search Paths -> + -> "$(SDKROOT)/usr/include/libxml2"
Add -lxml2 to "Other linker flag"
Search for "Other Linker Flags" as search in step 2
click on the "Other Linker Flags" row. Click the "+" and add "-lxml2" to the list.
Change your project type to ARC -> No i.e Automatic Reference Counting to No
You can search ARC as per in step 2
Xcode 4.5
I have used The CW's solution entirely.
The only exception is that $(SDKROOT)/usr/include/libxml2 didn't work for me, and I had to add "$(SDK_DIR)"/usr/include/libxml2 to my Projects Header Search Paths and User Header Search Paths.
After that project builds successfully.
EDIT: I have Google GData project inside my project (called MyProject) (my project uses). GData requires libxml. To build project MyProject successfully, I add "$(SDK_DIR)"/usr/include/libxml2 to Header Search Paths of MyProject and no to Header Search Paths of GData . If I didnt add it to MyProject, project did not build).
I found this visual tutorial useful.
Blockquote
Adding libxml2 in Xcode 4.3.x
Adding libxml2 is a big, fat, finicky pain in the ass. If you're going to do it do it before you get too far in building your project.
Here's how.
Target settings
Click on your target (not your project) and select "Build Phases". Click on the reveal triangle titled "Link Binary With Libraries". Click on the "+" to add a library. Scroll to the bottom of the list and select "libxml2.dylib". That adds the libxml2 library 2 your project… but wait.
Project settings
Now you have to tell your project where to look for it three more times.
Select the "Build Settings tab". Scroll down to the "Linking" section. Under your project's columns double click on the "Other Linker Flags" row. Click the "+" and add "-lxml2" to the list.
Still more.
In the same tab, scroll down to the "Search Paths" section. Under your project's column in the "Framework Search Paths" row add "/usr/lib/libxml2.dylib".
In the "Header Search Paths" AND the "User Header Search Paths" row add "$(SDKROOT)/usr/include/libxml2". In those last two cases make sure that path is entered in Debug AND Release.
Then. Under the "Product" Menu select "Clean".
This is working and for Xcode5 too! Thank you!
Don't put libxml2.dylib under frameworks folder put it under root just below the root(Top left blue icon )
Then Click on the Project (TOP Left blue icon) ,GO to Build Settings,in the search box type "Header Search Paths" and then add the this "$(SDKROOT)/usr/include/libxml2"
This code resolve my issue hope it will help you fix this
#Aqib Mumtaz - I got it working by following the instructions in Parris' note above entitled "Adding libxml2 in Xcode 4.3 / 5 / 6". The step in using a Framework Search Path does not work and the compiler complains. Big kudos to that fella anyway!
I am using Xcode 6.2b3
Regardless of the version of Xcode you are using, it is buggy. Don't always assume that compile errors are real. There are many times when it does not follow header search paths and includes clearly listed are not found. Worse, the errors that result tend to point you in different directions so you waste a lot of time dinking around with distractions. With that said...
Recommend baby steps by starting with this exactly...:
create a single window Mac OS X Cocoa project called "Bench Test"
add XpathQuery into your project source directory directly in the Finder
click on the tiny folder icon under the project window's red close button
drag XpathQuery (folder if you contained it) into the project assets on the left of the project window's display
drag /Applications/Xcode/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/lib/libxml2.2.dylib into your project assets, at the bottom. This will add it into your "Build Phases" -> "Link Binary With Libraries" the easy way
click on the "Bench Test" project icon in the project assets column, top of the left
search for "Other Linker Flags" under "Build Settings"
add "-lxml2" (sans "") to "Other Linker Flags" under the "Bench Test" project icon column
search for "header search" under "Build Settings"
add "$(SDKROOT)/usr/include/libxml2" (sans "") to "Header Search Paths" under the "Bench Test" project icon column
add "$(SDKROOT)/usr/include/libxml2" (sans "") to "User Header Search Paths" under the "Bench Test" project icon column
Notes:
Mine would not work until I added that search path to both "Header Search Paths" and "User Header Search Paths".
To get to the libxml2.2.dylib in the finder, you will need to right click your Xcode icon and select "Show Package Contacts" (editorial: what a hack.. cramming all that garbage into the app)
Be prepared to change the linked libxml2.2.dylib. The one inside Xcode is intentionally used to ensure that Xcode gets something it knows about and in theory was tested. You may want to use the dylib in the system later (read up in this thread)
As I am using Xcode 6.2b3, I may have a newer libxml2.2.dylib. Yours could be named slightly different. Just search the folder for something that starts with "libxml" and ends with ".dylib" and that should be it. There may also be an alias like "libxml2.dylib". Don't use that right away as resolving an alias adds another variable into the Xcode "what could have bugs" equation.
For sanity sake, I make aliases of the external libraries, rename them to indicate which one they are, and keep them at the same level as the project file in the Finder. If they change location, change name, etc, the alias will have in it's Get Info, the original file's full path for later detective work to get the project compiling and linking again. (symlinks break too easy and are not natural to the Mac)
Last thing, and very important, see http://www.cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html where you can download XpathQuery and get some more goodness.
hope this helps.
If you happen to be developing something for Veterans, oh say an iPhone / iPad or Mac app, and are working against something called "MDWS" or "VIA" which are SOAP based interfaces to the medical record system... please contact me
I solved in three steps inXcode 8.0 + Unit Test Project
1) I added libxml file to the Build Phases.follow this link
2) I added Other Linker Flags as -ObjC (For both project and test project targets)
3) I setup Header Search Path as "${SDKROOT}/usr/include/libxml2" (Don't forget double quote in either side) (For both project and test project targets)
One of them will solve the issue. If not you have to apply all three of the above.
i tought i added wrongly, then i realize the problem is it not support arc, so check the support one here, life saver -> http://www.michaelbabiy.com/arc-compliant-gdataxml-library/