Use LLVM compiler by default for all Xcode projects? - iphone

I really enjoy switching from gcc to LLVM compiler, but do I have to switch manually every time I start a new project, or is there any way to make LLVM the default compiler?
I'm talking about xcode 3.
Thanks.

To accomplish this you will have to modify the project template within the Developer directory.
Navigate to where your templates are (probably something like: /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Project Templates/
Once you're there, you can select the project template you wish to modify, and locate it's .xcodeproj file. You can "show package contents" and inside is a project.pbxproj. You can modify this file and edit in the build setting to change the default compiler.
You'll have to find each section that relates to the build settings for each configuration (Debug, Release etc.), search for /* Begin XCBuildConfiguration section */.
Then you'll have to add GCC_VERSION as a key and com.apple.compilers.llvm.clang.1_0 as the value (1_0 in this instance is actually LLVM 1.6 according to Xcode. I also assume that the key-name GCC_VERSION only has GCC in it for legacy reasons, this will probably be updated to COMPILER_VERSION or something in the future).
Save the template and create a new project (You may have to restart Xcode if it was open). The compiler should be set to LLVM now.
However, I don't recommend you do this as LLVM still isn't 100% fit for deploying applications to users.

I don't believe there's an (easy) way to do this. (i.e.: There's no preference pane option for such a thing.) That said, the advice within the existing Setting GCC 4.2 as the default compiler on Mac OS X Leopard question should work #Jasariens answer seems ideal, if the per-project setting is proving tiresome.
However, LLVM isn't quite ready for prime time, so I'd really recommend not using it for the final deployment of apps, etc. (If you're encountering any odd issues, switch back to using GCC and they'll quite possibly go away.)
Incidentally, whilst off-topic, there's some great tips within the Hidden Features of Xcode question as well, so that might be worthy of a browse. :-)

The very easiest way (and smartest, I think) to do it for all future projects is to do the following 5 steps :
go to /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iPhone Base.xctemplate (you can simply Command + o (open) in Xcode then Command + Shift + G (go to folder), then paste this path)
open the file TemplateInfo.plist in Xcode
go to Project > SharedSettings > GCC_VERSION property and change its String value to com.apple.compilers.llvm.clang.1_0 : http://grab.by/a0dV
save the file
test by opening a new iPhone project.
You can do the same for other new project by going to, for example, /Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/Project Templates/iPad Base.xctemplate for the iPad projects, etc.
That's it.
Have a nice day everybody.

I’ve written a simple script that creates a fresh Xcode project with sane defaults. Might be worth adapting, so that you don’t have to set up every new project by hand.

All answers tell how to change default compiler value for new projects.
This is how to change directly the "iOS default" values in XCode for any projects :
EDIT the file (with sudo)
/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOSXXXX.sdk/SDKSettings.plist
Restart XCode and done!

Related

Xcode 7.3 autocomplete is so frustrating

There is a new autocomplete in Xcode. Probably might be useful because it checks not only beginning of names etc. But I found that very often it doesn't find a class name or a const name at all etc. I need to type in entire name by myself. Over all I found it makes my life harder and coding more time consuming. Is there a way to switch to the old way it used to work?
Xcode 7.3.1
In Xcode > Preferences > Text Editing
uncheck Enable type-over completions
restart Xcode
It seems that clearing the checkbox "Enable type-over completions" in XCode -> Preferences -> Text Editing does the trick. At least in my case autocompletion fell back to a sort of old way, so it could autocomplete the class name that I had to type in manually before that.
This is by no means an adequate solution, BUT it has allowed me to (barely) maintain my sanity the past few days:
After every build, you need to trash your Derived Data folder. You can find this folder in Xcode > Preferences > Locations > Derived Data. Just trash the whole thing and it'll kick off a re-indexing step that should restore proper autocomplete functionality.
Unfortunately, I've found that once I build, the autocomplete behavior reverts to its broken state.
just open Xcode derived data folder and delete the folder
/Users/yourUserName/Library/Developer/Xcode/DerivedData
then restart Xcode, now autocompletion works like a charm
I have the impression that some 'parts' of autocompletion simply fail after a while. I use to restart the Mac to get it back working. But sometimes it fails quite soon again.
Maybe the answer of #Alex Bykov combined with a restart will do the trick.
Anyway: auto-completion of Xcode always was crap. AppCode used to get it much better. Unfortunately not yet with swift.
Closed Xcode, opened Xcode, let it index, it worked.
it doesn't find a class name
As a work-around, you can try to press
Command + Shift + K and Command + B
Several times,it works temporarily.
Xcode 7.3.1
I will share another posible reason, that after couple of days we found out. We have multiple schemes, and in one of them, the bridging header was importing a file that didn't exist anymore. So, it didn't break while compiling and running (the header belongs to another scheme) but it caused the autocompletion to break (couldn't find any objective-c class).
Hope it would help someone!
After having tried different methods:
Delete Derived Data
Switching Module Enabled off in Build Settings
Full Clean
Relaunch
Only this worked:
Find any commented out (/* abc */) code after #end in your files and delete.
Credit to Max_B:
https://forums.developer.apple.com/thread/7439
In my case, other projects were auto-completing correctly. If all your projects fail to correctly predict code, then it might be a different issue, and the other answers might work.
I ran into this issue while trying to make an OS X app and I was able to fix this issue by making sure that the Xcode 7.3 documentation and the OS X 10.11.4 documentation was actually downloaded. Doing this fully restored my autocomplete functionality. My full instructions are below as well as in my answer to a similar question: https://stackoverflow.com/a/39420664/3444925
I had this problem myself and after looking through all the other similar questions & answers about this, I couldn't find a solution. However, I finally found what worked for me.
Go to Xcode -> Preferences -> Components. There you will probably find a screen that looks like the following:
This shows that the documentation has not has not been downloaded and therefore, any attempts to re-index or re-build the application without downloading the documentation would prevent you from being able to use the autocompletion functionality.
Once I downloaded the Xcode 7.3 Documentation and the OSX 10.11.4 Documentation, this was enough for me to get the autocomplete functionality back (I was trying to build an OS X app, so feel free to download as much documentation as is relevant for you).
I didn't run into this until I created a couple of new class files. Other classes worked fine, but autocomplete would NOT work for anything in the new files...
FIX (for me) - I had to add those files to ALL of my targets, including the unit test targets even though I wasn't using them yet.

Restore Project Settings in XCode

How can I restore Xcode project settings? I can't see few settings (like Targeted Device Family, iPhone OS Deployment Target, etc.) after I gave my Macbook to my friend. :(
I also saw that the info.plist file was not in the project, I recovered it via TimeMachine though, the Base SDK is also missing. :( She messed all things up, I don't know why she went in there. Anyways, is there any way to restore the settings?
Unfortunately, the snapshot that I have is also very old. :(
No way to restore them. You can set the base sdk on the project info screen.
Project > Edit Project Settings > Base SDK, Check the same for your Target.
Is this issue occurring for a specific project, or all projects? If you create a new project, what happens?
I forget the exact syntax, but different versions of XCode handle project files slightly differently. A new SDK (and version of XCode) couldn't read my project file right (same symptoms you explain).
In my case, there were 2 different SDK settings in the project file due to 2 separate versions of XCode editing the file (this could be very likely if you restored from backup and had upgraded SDKs in the interim).
Look for something like:
SDKROOT = iphoneos4.2;
Or really, just look around the text that contains the build settings (all of your build settings are stored in the file in flat text) -- you may see something related to SDKs where there are 2 lines very similar right next to each other. That'd probably be your problem. If you don't know which to delete, try both and then re-set the setting using the interface.
Of course in any case, you should back up your project file (project.pbxproj) before trying any of this.

Is there a way I can compare code in an old Xcode project with a new Xcode project?

I have a developer who has been working on an old Xcode project for me. Is there a simple way I can compare files in his new Xcode project to the ones in the new Xcode project to quickly see which changes he's done and how the old code has changed? He's be procrastinating and finally i have twisted his arm to send me the new Xcode project. He claims that the old code was rubbish, including the old coder too, so I'd like to see if he's actually done any changes to the old guy's project or is just plain and simple, 'a talker'.
Sure, use the "diff" command (from a terminal window).
If the two projects are in folders "old-project" and "new-project", respectively, you would do something like:
diff -r old-project new-project
The "-r" will recursively compare corresponding files in subdirectories.
ps. this should also be a wake-up call to you that's it's time to put your project into some kind of version control system (such as svn). If you had your project in source control, there would not be any question about exactly what had been changed, when, and by whom.
you can use FileMerge. it is under Developer/Applications/Utilities/FileMerge

Xcode Project Code Changes Not Updating 100% After Save-Build-Run

When I make code changes to my iPhone game project in Xcode, and then do CMD-B + Enter, I expect the project to be saved, build and run on the simulator with the latest. What is happening though, sometimes, is that it doesn't pick up a small change I make unless I clean the project and then build.
I'm a long time Java person and newish to C-based languages and it's compiler. Can someone explain to me what is cached after each build that does this and how to change my project settings to avoid having to clean every time? Or tell me the bad news that this is part of C development? Not trying to bash it - I get compiled JSPs stuck in the working cache often in Java, too. :P
UPDATE: Does this have to do with the location of my builds at all? That's the only thing I can think of that's changed from a build config perspective.
Had a similar problem, I reset content and settings in the iPhone simulator
Seems odd to me, because I never get this problem in XCode. It's not a common issue with C or anything. The tools for C-based languages usually do this just as well as the Java ones.
Go to Product Menu and choose Clean and then choose Build. Thats it.
In the Xcode Build Preferences make sure that "Unsaved Files" is set to "Always Save". If not, Xcode will not autosave files before building and will use the last version saved to disk.
In case anyone still comes across this (as I was having this issue today on Xcode 5.1), all I had to do was open a new tab and close out the tab I was working in. Some sort of tab bug in Xcode.
I am not sure about this, But in case if you are using git, go to xcode preferences -> Source control -> General
Uncheck Refresh local status automatically
Uncheck Fetch and refresh server status automatically
Uncheck Add and remove files automatically
Uncheck Select files to commit automatically

Build Error - missing required architecture i386 in file

I'm getting this error when building my iPhone application:
ld: warning: in /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.sdk/System/Library
/Frameworks/UIKit.framework/UIKit, missing required architecture i386 in file
It goes the same for all the frameworks in my app. It's very weird since this was not happening earlier.
This happens when you add a framework to your project and unintentionally copy the framework into your project directory.
The fix is to check your project directory (where you store your project on disk) for any iphone SDK *.Framework files and delete them.
Project will build fine afterwards.
I had this same problem, and the solution turned out to be an easy fix. Backup then open project.pbxproj (located inside your project file bundle) in TextMate or TextEdit and search for the section titled "/* Begin XCBuildConfiguration section */". Look for a key named FRAMEWORK_SEARCH_PATHS and delete it and it's contents (once per build configuration, so I removed it in two places). Here is an example of what I deleted:
FRAMEWORK_SEARCH_PATHS = (
"$(inherited)",
"\"$(DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.sdk/System/Library/Frameworks\"",);
My project now build for both the iPhone device and the iPhoneSimulator.
What has happened here is that Xcode has mysteriously added a "Framework Search Paths" entry that points to a particular iPhone device SDK. For example, mine was recently set to:
$(DEVELOPER_DIR)/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.1.sdk/System/Library/Frameworks
This leads the compiler to find frameworks of the incorrect architecture. Removing any values under the "Framework Search Paths" key in your target's build settings will resolve the issue.
I just wanted to mention that in XCode if you go to "Edit Project Settings"
and find "Search Paths" There is a field for "Framework Search Paths". Updating this should fix the problem, without having to hack the project file!
Cheers!
Jesse
Check that you didn't copy the framework into your project when you added it. If you copied it, it can't find the original paths. To fix this problem. Delete the AVFoundation framework from your frameworks folder in your project, then add it again, but this time, make sure you don't have copy check marked.
This fixed it for me!
I fixed it in a different way.The reason why i was getting this error was that i added security.framework twice in my project.I was not able to see security framework in xcode ,i opened the project in finder and found this framework which i deleted and problem solved.
If your app is meant to run on the device, make sure you are not trying to run in it on the simulator. May sound obvious, but check anyway.
Though it is possible that something got deleted, it has been my experience that something gets screwed up in the project file. I have yet to pin down what that "something" is. I've had similar issues when the SDK installation is just fine. There are a couple of options.
First, add all of your files to a new project. This seems to usually work. Kind of a pain, though.
Second, you can right-click project in XCode/Get Info/Build/Library Search Paths. Add new paths similar to /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.sdk/usr/lib. Add appropriate versions of that string for each version (2.2.1, etc) and platform (simulator or iPhoneOS). Perform a similar action for Framework Search Paths if frameworks are your problem.
Third, which is more work but more reliable, is to open project.pbxproj from within MyProject.xcodeproj (Textmate is good for this). Look for "/* Begin XCBuildConfiguration section */", then "LIBRARY_SEARCH_PATHS" and "FRAMEWORK_SEARCH_PATHS". Add or modify the paths as appropriate, and save the file.
In any case, a pain in the butt, and I'd sure like to pin-point the cause because I've had this happen a couple of times. Project builds fine, then just up and refuses to do so with what seems to be little reason.
"Edit Project Settings" and find "Search Paths" There is a field for "Framework Search Paths". delete all!!
It just happened here to me as well. Thanks to a great partner we found the answer. Your Xcode may be pointing to the simulator ..change it to a IOS device instead ..built smooth after ....
Run the file command on the framework from Terminal:
file /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.sdk/System/Library /Frameworks/UIKit.framework/UIKit
You should get back a message telling you which architectures the UIKit binary is compatible with. If you don't see "i386" listed, then you've somehow managed to remove the i386 version of UIKit, which will mean that you can't build for the simulator.To fix that, you'll have to re-install the SDK.
If you get some other error, hopefully it'll help you figure out what the actual problem is.
I just want to let you know that In my case, I was having the same problem, I realized that I had an older Xcode folder called Xcode3.1.3 I just rename it because it was an older version and that did the magic for me.
Check your library search paths in your target settings. Sometimes goofy libraries get entered in there and this will give you a similar error.
You can remove all entries in this section.
I'd just experienced something slightly different, because I work on my own library (WM_GSRecognizerLib), but the error is the same.
What'd happen: due to some updates, the path targeting the lib to include (.a) was from the "Debug-iphoneos" folder (where it is generated). Compiling for Generic iOS Devices worked fine, but not for simulator, complaining for the missing i386 architecture.
What I did for this issue, is to also include the binaries from the "Debug-iphonesimulator" folder.
It can help for this topic, because the explanation is here: devices require binaries for arm64/armv7/armv7s, while simulator does need i386.
My solution was to set on simulator target debug YES, just look on git status to see the new line added as architecture only on .project. if you don't set this the build will run to all architectures and will show some missing architecture like i386 or other.
NOTE THAT obviously the main issue is to use some framework that implements some kind of specific architecture.
I too got the same error am using xcode version 4.0.2 so what i did was selected the xcode project file and from their i selected the Target option their i could see the app of my project so i clicked on it and went to the build settings option.
Their in the search option i typed Framework search path, and deleted all the settings and then clicked the build button and that worked for me just fine,
Thanks and Regards