Minimizing the use of Xcode - how to quickly build and go from source code? - iphone

I realize I have to use Xcode to develop for the iphone, but I'm trying to build apps from raw source code generated outside of Xcode.
For example, I would like to "Build and Go" the apple demo "TheElements" (here). (I use this example because it has no .xib files - so Xcode is not needed for the UI).
It works to just unzip and open the .xcodeproj in there, but what if I had generated this code elsewhere and haven't yet used xcode? I.e., I have a directory of files (the contents of the .zip without the xcodeproj stuff):
./Default.png
./Images/*.png
./Classes/*.{h,m}
./Icon.png
./main.m
./Elements.plist
./Info.plist
./TheElements_Prefix.pch
Can I quickly (automatically?) get this built and running in the simulator?
I guess the question also relates to what information is really stored in the xcodeproj. Ideally, there would be some scriptable method for generating the project.pbxproj file, but sadly can't find this.

You might think of the Xcode project file as a glorified Makefile (if you're coming from the Unix world) or a VC solution file (if you're coming from Windows). It's a description of the dependencies between components and the steps required to build, link, and deploy those components. There is no more fundamental "Build and Go" than that.
On the iPhone, Xcode is required to build a viable application (technically, you could chain up the command line invocations used by Xcode—check the build log—but you'd be pretty crazy to bother). You can use a command line invocation (xcodebuild) instead of using the Xcode GUI app, but you still need a project file.

Related

How can I debug in a framework in Xcode?

I have two projects, one is the networkLib for login and some other network function, the other is the usingLibDemo. So I have all the source code of both projects.
The networkLib project outputs a framework, called myNetKit.framework, which is used by usingLibDemo.
Now I successfully use myNetKit.framework to login, but sometimes it crashes, maybe in main() without stack information, but sometimes Xcode gives me the stack info like below:
So I know where it crashes:
But the Utils.m is not exposed, how Xcode gets the stack info and the crash line, and eventually open the source file for me? Because that I have the source code in my disk?
If so, how can I debug the myNetKit.framework step by step, when it is not crashed?
Thanks a lot for any tips.
If someone would have the same question in future (now I am using Xcode 8):
You can:
build your framework project (in this example "networkLib")
copy project output ("myNetKit.framework") to destination project ("usingLibDemo")
run destination project ("usingLibDemo") on your device
stop process
launch app from your device manually ("usingLibDemo")
open framework project and Attach to Process of your app (launched in step 5). In Xcode 8: Debug->Attach to Process-> Select name of your app.
Don't forget set some breakpoints in your framework project.
When the library is built with all symbols, it contains full paths to the each source file embedded in itself. You can actually see this if you open the .a with a hex viewer. With this in place, the XCode will know how to get to the source file.
Setting breakpoints is somewhat more challenging. You basically have to make XCode slowly discover source files from your library by stepping into methods in those file. Once XCode has opened the file, you can set the breakpoint anywhere in it.
It is a bit painful but it works and you do not have to make the library project a subproject if you do not want to.
The following works considering the scenario that you have the framework project separately and added a.framework to some project B.
Go to your project B, add a breakpoint anywhere.
Go to the breakpoint view(where all breakpoints can be seen as a list), right click your breakpoint and click move breakpoint to user.
Go to a.framework and repeat step 1 and 2 but for your framework project.
Now switch back to project B and run the project on simulator/device.
You'll now see program stopping at the breakpoints set in the framework as well.
You can also add the entire library (networkLib) project into your project and link the library dynamically by adding dependency in project settings. So you can have all the source code within your project. So you can debug it in run time.
Use XCode Workspace when you deal with multiple framework projects. When you use a workspace, breakpoints will work and you can find your crash without loads of back and forth debugging. It will be much easier to manage your frameworks in the long run.
You should debug the project networkLib which outputs the framework separately. The framework do not have app like structure so a framework file within other project can't be debugged.

Use LLVM compiler by default for all Xcode projects?

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!

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 build configurations search paths

my iphone app builds fine in debug configuration, but when i change it to release, i get hundreds of errors, starting with "CoreServices/CoreServices.h: No such file or directory" in AudioFileComponent.h - part of the AudioToolbox framework.
i can't find where in the project/build settings is responsible for this.. thanks for any help.
I would recommend the following:
Open up your debug target's build settings by right-clicking on the target, hitting "Get Info", and selecting the Build tab.
Select All (Command-A) so the entire contents of the Build setting panel is selected, then copy it to the clipboard.
Paste the contents of the clipboard to an empty text document
Repeat steps 1-3 for the release target of the same project
From there you can use a diff utility or some other method to compare the contents of the two files, which will show you the settings that differ between the two configurations. Some of them will make sense (e.g., optimization settings) whereas others will not. Most likely there is a setting that differs between the two that will resolve your problem.
Another thing you can do is build one of your source files in debug mode, and in the Build Results window copy the contents of the command line to a text editor. Repeat for release mode. Then, replace each space in the command line with a newline (\r). From there you should be able to do a rough side-by-side evaluation of the differences between the two compile instructions, and may be able to figure out what's missing from that.
In general this helps you get a better feel for exactly what XCode is doing under the hood to build your project, which is a good strategy to practice no matter what tool you are using for development.
i think the problem was because i had the audiotoolbox package in the wrong place, it wasnt in system/library/frameworks like it should have been. (this doesnt explain why it built ok in debug though)

Xcode iPhone app package missing files

I'm struggling to figure out what exactly it is that decides which files go into the .app-package when compiling an application in Xcode. I've noticed that most image files go there automatically, while others like yaml-files or psd don't, and I cant find anywhere to set this. So, how do you do this?
Look at the build phases for your application target. You'll find that recognized image files were added to the Copy Bundle Resources phase. To copy files of a type that Xcode doesn't recognize, you can add a Copy Files build phase.
If all else fails, read the documentation.