- cmd-} indent right
- cmd-{ indent left
Sunday, July 12, 2009
XCode: The Great Escape (esc)
Wow! Once you know this vital piece of information your whole life will change.
Once you know the magic keystroke all your dreams will come true!
Are you ready? Huh? Are you?
OK...here it comes...you sure you are ready?
The magic keystroke is 'esc'
When in XCode and you click the 'esc' key you get amazing AUTO-COMPLETION.
Use it and enjoy life.
You're welcome.
I may have exaggerated a little bit. :-)
Saturday, July 11, 2009
iPhone App: Amazing Polygon App
Here is a little application I whipped up tonight for the iPhone. It is based on an assignment from the Stanford course.
Anyway, I call it the "Amazing Polygon App". What it does is calculate the number of degrees, radians, and description of a polygon with a specified number of sides.
There is an increase and decrease button. As you click the buttons the number of sides is incremented (or decremented) and the display is refreshed.
Simple but to the point.




Lessons learned:
- Once you have your initial user interface put together, chances are you'll want to modify it in some ways later. You can easily rearrange the positions of the controls in the Interface Builder.
- To add new controls is not a big problem either. Simply add the controls in Interface Builder. Then in your Controller add instance variables representing the controls and be sure to properly decorate these instance variables with the Cocoa Macros to let the Interface Builder know about them. Once this is done, the instance variables will appear as outlets in the Interface Builder for the controller. Now it is a simple matter to add a connection between the outlet and the control on your user interface!!
Friday, July 10, 2009
XCode: Go to Counterpart
that looks kind of like a standard copy to clipboard button (2 overlapping pages). If you hover over this button it says "Go to Counterpart".

NOTE: You can modestly change the behavior of this within the XCode Preferences under the General icon:

If you are viewing an Objective-C header (.h) file or an Objective-C implementation (.m) file then this file will be enabled. Clicking the file swaps the contents of the current edit window with the corresponding file. In other words, if you are looking at the header file and you click the button then the contents of the edit view will show the corresponding implementation file.

NOTE: You can modestly change the behavior of this within the XCode Preferences under the General icon:

If you forget about this icon you can always use the keyboard shortcut: opt-cmd-UPARROW
XCode is flexible...even does the splits!
The XCode development environment is Apple's slick IDE (Integrated Development Environment) which is used to write Apple Applications (MACOS + iPhone).
The main project window has 3 main areas:
- West: Groups & Files
- North East: File Names
- South East: Edit Views
If you look closely in the views area you'll see an itsy-bitsy icon near the right scroll bar. Float over it. It says: "click to split the editor view". When you click this icon the edit view turns into 2 panels with the same content. You can then click on either edit view followed by clicking on a file and voi-la you'll have two separate files viewable at the same time.
I find this helpful when looking at Objective-C header and implementation files.
Interface Builder

I am using Interface Builder version 3.1.2 (see image above). This kind of jives with the version of XCode I am using. See below.
Note: when developers talk about the Interface Document Window they are really describing the .xib file (or the window presenting the .xib) file. Recall, the .xib file contains the interface design document that archives the elements of your user interface. Once saved the .xib file contains the archived version of your user interface as well as any state specified at design time.
Controller objects in the context of interface building is an arbitrarily named object that has been added to the user interface document. This object has outlets (instance variables) as well as actions (what it does).
You define the object's outlets and actions using the Identity Inspector (cmd-4).

So we've created:
- some basic user interface with some user interface components (e.g. 2 buttons and 2 labels)
- a controller object (to be used to control how the user interface is used.
Now we want to connect the UI components to the controller. Welcome the Connections Inspector (cmd-2)
BTW, you may have observed a pattern here with regard to how you can activate the various inspectors:
- cmd-1: Attributes Inspector
- cmd-2: Connections Inspector
- cmd-3: Size Inspector
- cmd-4: Identity Inspector
Controller classes are defined within the Interface Builder. Now we need to connect it to the application...by creating/generating an actual source file. NOTE: if we simply try to run the application after creating an object within the Interface Builder there will be an error as when the NIB is unarchived it will try to instantiate a Controller class...but we have not yet generated the source for it and compiled the source.
You'll get an error like the following:
2009-07-10 16:40:15.586 HelloPoly[4322:20b] Unknown class Controller in Interface Builder file.
Don't despair! In Interface Builder select the Controller object and then do a File -> write class files.
Be sure to look at UIKit Reference API
One thing to remember is that everything you can do in Interface Builder you can do programmatically.
xib ~ nib ~ Interface File
The interface file
It is kind of like the serialized (or archived) version of what you put together at design time.
When you run your application and a .xib file is loaded the objects are deserialized (unarchived) and live objects are created...and their state becomes what it was at design time.
.xib files are created and manipulated (designed) with an application called the Interface Builder.
btw, on a MAC-OSX computer the Interface Builder is located in the /Developer/Applications directory.
From the Stanford course I've learned that the Interface Builder accomplishes the following jobs:
- Layout and configure the user interface
- Define a controller class and create an instance of that class
- Connect the user interface and the controller
- Generate source files for the new controller class
From Apple's site:
Key Interface Builder Features
- Helps you design Aqua-compliant user interfaces with the "Snap to Aqua Guidelines" feature
- Creates both Cocoa nibs and Carbon nibs
- A key part of the Cocoa application development process - lets you subclass, connect objects, and establish default values, helping your application require less code
- "Test Interface" mode lets you try your UI without writing any code
- Spell Checks your UI text as you go
Subscribe to:
Posts (Atom)
