Nov 11

Xcode introduced Clang LLVM compiler integrated into the IDE. By default, these only run via Build and Analyze. However, this static analysis is insanely useful, and can catch “retain leaks” quickly. Therefore, I always analyze on every build.

If you wish to do the same, simple Get Info on the Project. Under the Build Options, check the “Run Static Analyzer” option.

Tagged with:
Nov 04

I banged my head against figuring out how to make use of third-party frameworks. Unfortunately, this seems like a task that most developers expect users to instinctively know how to do and never explain it otherwise. I was somewhat frustrated and having trouble getting my project to make use of the third party Framework for both compiling and running. After some banging my head on the wall, a post on StackOverflow and a few bruises later I got it working.

XcodeScreenSnapz005The first thing that I needed to do was build the framework. The particular Framework I am using is MPOAuthConnection which provides an SVN link and a project. I, therefore, needed to build the Framework in that project. Xcode is nice enough to put Products in the item list. I simply dragged the MPOAuth.framework product from the MPOAuthConnection Project to my Celery Project. Dropping it into the Linked Frameworks section and choosing to copy the files.

Using the proper imports, this admittedly tripped me up a bit, because I was working in the project and doing “file.h” imports rather than the proper <library/file.h> imports, my project would compile.

However, I was getting odd errors on running, where it couldn’t find the files needed (and some strange memory problems). Turns out, when you add a new Framework, you also have to have the build system copy the framework into the Application product. To do this, you need right click on the target for your application, Add -> New Build Phase -> New Copy Files Build Phase. The only setting that needs to be set is the Destination must be set to “Frameworks”.

XcodeScreenSnapz006

Here is the key element that I could not figure out for about an hour. You must drag the Framework from the Linked Framework to the new Build Phase you just created.

XcodeScreenSnapz007

Viola! You should be set.

Tagged with:
Aug 14

When developing you are going to do something wrong (you are, stop denying it) and generate an exception. When this happens the debug console window will appear and dump a rather large stack track of values (I’m assuming these are memory address, but have no idea how this would be useful).  Above that stack trace is the reason, something like:

*** Terminating app due to uncaught exception ‘NSInvalidArgumentException’, reason: ‘*** -[Image badMethodCall]: unrecognized selector sent to instance 0xd22820′

This typically gives you enough information to figure out what the problem is. If you need the line which generated it, the method trace window can give you more information. Simply trace down until you see your code (will be in bold type). That should point you to your problem stop.

XcodeScreenSnapz002

Additionally, you can break whenever an exception is thrown before the system crashes. This can, in many cases, give you a better stack trace of the exception.

Open the Breakpoints view and add “objc_exception_throw” symbol as a general breakpoint.

Tagged with:
Aug 03

Quick tip on locating the physical location of a file on disk while working on it in Xcode. Simply right-click (or command-click) the title bar. This will give a list of the directory structure. Clicking on any directory will open Finder at that location.

XcodeScreenSnapz001

Tagged with:
Jul 31

If you updated your iPhone to OS 3.0.1 (which you should), it will break your Xcode link to build to the device. To fix this you need to follow the instructions at:

http://adcdownload.apple.com/iphone/iphone_sdk_3.0__final/iphone_os_3.0.1_advisory.pdf

Tagged with:
Jul 30

When playing with MapKit and the new 3.0 ability to add Google Maps inside your application, don’t forget to include MapKit.framework to your project. You’ll save yourself about half an hour of grief.

By the way, MapKit is cool.

Tagged with:
Jul 18

This site by far has some of the best tweaks to Xcode I’ve seen. Coming from other development environments, there have been quite a few annoyances that I couldn’t get past, this one kills almost all of them! Long live “All-in-One View”.

http://www.mobileorchard.com/14-essential-xcode-tips-tricks-and-resources-for-iphone-devs/

Tagged with:
Jul 15

↑⌘E – Zooms the Editor In/Out. (Removes the files list above the Editor).

⌥↑⌘T – Shows the current file in the Editor in the Class group tree.

Tagged with:
Jul 14

Here are a few keyboard shortcuts that I have learned to love:

  • ESC – Kicks in Autocomplete, including a drop down list of all available properties/methods for the current symbol.
  • ⌘Enter – Builds and Runs
  • ⌥⌘↑ – Switches between header and source files.
Tagged with:
Jul 11

When refactoring existing code, be careful to ensure that your Interface Builder outlets are still correct. For example, if I have a simple controller class with the following attributes:

XcodeScreenSnapz004

They are defined as IBOutlet’s and are, therefore, connected in Interface Builder to UI elements.

Interface BuilderScreenSnapz001

Now, let’s say we wish to change the name of “switcher” to “switchElement”. Obviously, the worst thing we could do is make the change manually, even without the Interface Builder connections we’d have to manually update both the .H and the .M files. So, we should make use of Xcode’s refactoring mechanism.

Right click on the attribute in question (“switcher”), and select Refactor

XcodeScreenSnapz005

This will bring up a new Dialog with the “rename” option already selected. Type in the new name, it will identify what files will be changed. You’ll notice that the .H, .M and the nib file are selected for changing.

Once you apply the change, you’ll need to revert the nib in Interface Builder to the version on file. However, Xcode doesn’t handle everything for you, there is one more step that you have to take care of. If you open up the connections part of the UI, you’ll see that it did, in fact, update your connection. But, the old outlet name still appears as another entry and the new name has a warning. The warning is that the class doesn’t have an outlet with the new name.

After banging my head for awhile trying to figure out why they wouldn’t take the final step during a refactor I realized I needed to do one more thing. Save the .M and .H files. Now, everything is in sync and working properly.

Tagged with:
preload preload preload