UIImagePickerController

Let’s dive into the hardware of the iPhone and iPad, both of which now have a camera.

UIImagePickerController
The default use of a camera in iOS applications is the UIImagePickerController. You can take pictures from the Photo Library, Saved Photos, or Camera itself.
There are certain steps you need to take when you want to implement UIImagePickerController into your apps. First off, you need to check the source availability. Some devices do not have cameras, and thus this step is crucial (although Apple does check for you as well, it is good to check it yourself to be sure). Next step is to set the source type, which is where you want to select the photos from, be it the camera or photo library or saved photos. After which, you would want to set properties such as the media types, photo or video. Finally, you assign the delegate to yourself and present the controller modally. Take note that these controllers are always modally presented.

//Check source availability
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
//Create UIImagePickerController
UIImagePickerController* picker = [[UIImagePickerController alloc] init];

//Set image picker source
picker.sourceType = UIImagePickerControllerSourceTypeCamera;

//Set image picker media types
picker.mediaTypes = [NSArray arrayWithObjects: (NSString *) kUTTypeMovie, (NSString *) kUTTypeImage, nil];

//Set image picker delegate
picker.delegate = self;

//Present image picker
[self presentModalViewController:picker animated:YES];

}

* Add MobileCoreServices.framework or
 #import

First off, we check the source availability by calling isSourceTypeAvailable. Next we create the UIImagePickerController, set the source and mediaTypes. For mediaTypes we create an array that includes both Movie and Image, in this case. Make sure you add the MobileCoreServices framework and import the UTCoreTypes file first.
Finally, we set the delegate to the view controller and present it modally.

There are many properties you might want to take note of while writing for your iOS apps, such as whether to use the rear or front camera, the quality of media, and whether you want to use flash or not.

UIImagePickerControllerDelegate
After implementing all of the above, you still need to implement the delegate methods as well. Your final images or videos will be stored in an NSDictionary that is returned in the imagePickerController didFinishPickingMediaWithInfo. Here is where you would want to store the images somewhere, and then dismiss the controller. There’s also a cancel method if the user chose to cancel taking a photo instead.

Contains your original and edited images (save them!)

– (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info; 

Dismiss controller here
– (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker;

After implementing all of the above, you still need to implement the delegate methods as well. Your final images or videos will be stored in an NSDictionary that is returned in the imagePickerController didFinishPickingMediaWithInfo. Here is where you would want to store the images somewhere, and then dismiss the controller. There’s also a cancel method if the user chose to cancel taking a photo instead.

Saving Media
To save media, we have to use the following methods, UIImageWriteToSavedPhotosAlbum, and UISaveVideoAtPathToSavedPhotosAlbum. For videos, you need to check if the path is compatible to be saved in.

UIImageWriteToSavedPhotosAlbum

Optional completion callback 

UIVideoAtPathIsCompatibleWithSavedPhotosAlbum 
UISaveVideoAtPathToSavedPhotosAlbum

Augmented Reality
If you want to use augmented reality in your apps, you definitely can. The few properties that you should be looking at are showsCameraControls, cameraOverlayView, and cameraViewTransform. A third party kit that was recently developed is available for free to incorporate into your apps at www.iphonear.org.

ARKit (http://www.iphonear.org)

showsCameraControls
cameraOverlayView 

cameraViewTransform

Web Services XML or JSON

Most web services are exposed via RESTful interfaces such as XML or JSON.

XML
XML looks like this. Basically it starts off with the version number, and then a dictionary or array within. This dictionary or array can contain even more dictionaries and arrays or any other objects. The next thing we have to do is to parse through this message.


Steve Paul Have a good weekend!

XML Parsers
There are two types of XML parsers, the DOM and SAX parsers. The DOM notifies you when it runs through the tree. A SAX parser reads and builds up an in-memory representation of the XML. Both has its advantages and disadvantages.

Many to choose from (C / Obj-C)
NSXML, 
libxml2
TBXML
TouchXML
KissXML
TinyXML
GDataXML

Advantages/drawbacks
Validation
XPath

For the parser itself, we have many to choose from. The included parsers are NSXMLParser and libxml2 parser. The rest are created by third-party developers and have proven to work. Each parser, again has its own advantages / disadvantages to watch out for, such as validation of each step as it parses through the XML, and also XPath which functions as an index.

NSXMLParser
Let’s run through the included XML parser, NSXMLParser. The first thing you have to do is to create the parser, set the delegate to self, and any properties you may wish to set. During the creation of the XMLParser, be sure to init with whatever XML you have.

Create parser/set delegate & properties

NSXMLParser *parser = [[NSXMLParser alloc] initWithURL:myURL];
parser.delegate = self;
parser.shouldProcessNameSpaces = NO;

Parse

[parser parse];

Receive from delegate methods

 – (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
– (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName 
 – (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string

JSON
Another form of RESTful interface is JSON, which is Javascript Object Notation. Here’s how the same message looks like in JSON. This is more human-readable, according to many.
To parse JSON, we can use a third-party JSON framework, called SBJSON. SBJSON was created by Stig Brautaset. It was originally named JSON-framework but renamed soon after to SBJSON.

SBJSON
To use SBJSON, we simply download, drag and copy into our own project. If you are using XCode 4, you might want to check out how to link projects instead of copying them over. The instructions are a bit more complicated, but are also found in the same SBJSON link.
The next thing we need to do is to import JSON.h, create the SBJSON parser, and then parse it into an NSDictionary. If we do not know what the final object is, we can simply use the id type. Download, drag and drop, copy into folder.

Import/create/parse

#import “JSON.h”
SBJSON *parser = [[SBJSON alloc] init];
NSDictionary *object = [parser objectWithString:json_string error:nil];

NSUserDefaults

There are a few ways we can persist data on the iPhone. The first one is to store data securely. We can make use of the Keychain framework that Apple has provided.
NSUserDefaults is another way of storing data, but for non-sensitive info such as user settings which do not need to be encrypted. NSUserDefaults will be further explained in the next slide.

Set a value
[[NSUserDefaults standardUserDefaults] setObject:myValue forKey:myKey];

Retrieve a value
[[NSUserDefaults standardUserDefaults] objectForKey:myKey];

Synchronize
[[NSUserDefaults standardUserDefaults] synchronize];

NSUserDefaults is a simple way of storing non-sensitive data. We can set a value by calling NSUserDefaults standardUserDefaults set Object. Basically, it works like an NSDictionary. You can easily set and retrieve values.
However, this time round, you need to synchronize. Synchronize basically works like a save. After changing variables, you might want to call synchronize to save NSUserDefaults. NSUserDefaults saves every now and then, but to make sure you can simply call synchronize.

WebKit Projects

There are many exciting projects that we are actively working on in the WebKit source tree. To find out more about each project you can visit that project’s home page. If you are interested in starting a new project in the WebKit tree, contact WebKit.org!

General Projects

Web Site Compatibility
The most important project that we are working on (and the one that receives the most attention) is web site compatibility. Our top priority is ensuring that WebKit works with as many web sites as possible. This is a cross-functional project that touches many areas of the code.

Performance
Our second highest priority after compatibility is performance. Find out about our performance measurement tools and policies here.

Code Cleanup
We have a number of tasks in mind for code cleanup. In addition to reformatting existing code to match our coding style guidelines, we also have plenty of work to do moving WebKit code into WebCore now that both frameworks are open source.

Portability
Making the WebKit code more portable to other platforms is also a priority. We would like to begin integration of ports to other platforms, such as the GTK+ port of WebCore. Find out about our plans here.

Documentation
Want to add documents to the WebKit web site? We’re interested in architecture documents, support charts and any other documents you think will help people trying to use WebKit.

Specific Projects

CSS (Cascading Style Sheets)
Cascading Style Sheets (CSS) is a simple mechanism for adding style to Web documents. It is a W3C standard.

DOM (Document Object Model)
The Document Object Model is a platform and language neutral interface that allows code to dynamically access and update the content, structure and style of documents. It is a W3C standard.

HTML/XHTML (HyperText Markup Language)
The HTML project is concerned with the implementation of the HTML and XHTML specifications from the W3C. In addition to the W3C work on HTML and XHTML, we are also interested in the extensions to HTML proposed by the WhatWG in the Web Apps specification.

HTML Editing
The HTML editing project provides rich text editing capabilities both as WebKit API for applications and through support of contentEditable and designMode for use in Web pages.

HTML Forms
The HTML form controls project is about the code to support the form controls that are available in HTML and XHTML. We would like to extend forms to support the work of the WhatWG (in particular the Web Forms specification). We also plan to change how the forms are implemented in order to improve performance and portability of the controls.

JavaScript
JavaScript is the primary scripting language of the Web, and WebKit’s JS engine is one of the fastest out there. Find out about some of the interesting improvements planned for the JavaScript interpreter.

Layout and Rendering
For work on the layout and rendering of XML/HTML+CSS. This includes block and line layout, table layout and extensions like the XUL box layout. This also includes work on rendering and display issues.

MathML

MathML is a specification for the inclusion of mathematical expressions in Web documents. Although this is not yet implemented in WebKit, we are keenly interested in developing a fully integrated implementation.

Plug-ins
WebKit supports two types of plug-ins, cross-browser plug-ins using an enhanced form of the Netscape plug-in API and WebKit plug-ins that are designed for use by embedded applications that need to display native OS X content integrated with the Web document.

Printing
Find out about WebKit’s printing architecture here and about planned improvements to make page breaks work more cleanly when splitting up objects like HTML tables.

SVG (Scalable Vector Graphics)
SVG is a standard from the W3C for describing two-dimensional graphics for Web documents. This is not yet implemented in WebKit, but we are very interested in merging KSVG and the KDOM work into our code base to achieve a fully integrated SVG solution. If you want to see Dashboard widgets that use SVG, come on in and help make it happen!

WebKit API
The WebKit embedding API provides clients with a public API for loading, displaying and manipulating Web content. WebKit clients can find out about plans for the API and get involved in the design process.

Web Page Accessibility
WebKit has accessibility features designed to work with the VoiceOver technology of OS X. Get involved and make suggestions for how this support can be improved in future releases. We are also interested in how to generalize our current accessibility support to make it portable to other platforms.

XML (Extensible Markup Language)

XML is the foundation of WebKit’s document object model and in the future will be the preferred format for compound documents that use HTML, SVG and MathML together. This project covers the implementation of XML in WebKit and also other XML-related technologies like XPath.

XSLT

XSL Transformations provide the ability to take source XML and transform it into text, HTML or XML. This capability is a recent inclusion in WebKit, and there is still lots of interesting work to do in this area.

Base SDK Missing

For the noobie iPhone App Developer, their reaction to the error message “Base SDK Mssing” on an xCode sample code project, is similar to how I once felt about the “Blue Screen of Death” on a PC.

I got that same feeling of frustration when I loaded down the PageControl sample code from Apple. I couldn’t test the sample code in xCode because the “Base SDK Missing” error message was on display. I was using xCode 3.

It wasn’t the first time I’d come across this error, however, previously I’d found a solution.  I was desperately seeking a solution to paging horizontally and having PageControl.

I’ve solved my problems with the “Base SDK Missing” error message by trawling the internet and finding many generous people who share their knowledge.  So this “post” is me giving back to the app development community a little of what I’ve learned.

Solving the “Base SDK Missing” Error

Sometimes you will try to open an old xCode project and you will find you can’t open it because the file gives you a “Base SDK Missing” message, as shown in the image below:

 Base SDK Missing error message as seen on the xCode Dashboard

The first time I came across this problem I was working through John Ray’s Book “iPad Application Development in 24 hours”. The problem raised its ugly head again when I tried to open the PageControl sample code from Apple.

I came across the problem again when I found an article about sample code titled “How to Add A Slick iBooks Like Page Turning Effect Into Your Apps”, published by Johann “John” Dowa on his website ManiacDev. The article led me to a download for an xCode project called Leaves created by Tom Brow and an extension of the same project called “Leaves Two Pages” by Ole Begemann.

I couldn’t open the projects because they gave an error message i.e. Base SDK Missing.  As mentioned, I’d had this message before but when I applied my solution, Solution 1, shock horror, it didn’t work.  So I hunted around the internet for more solutions and found Solution 2.  Both solutions are set out below:

Solution One for xCode 3
1) Select xCode File Name in the left side navigation bar and click on the blue Info button on the xCode Dashboard and a drop down menu will appear showing several tabs.

Screenshot showing selection of xCode File Name

xCode Dashboard Info Button
xCode Dashboard

2) Click on the Build Tab

Info Button Drop Down List showing Build Tab

3) Find “Base SDK” under Architecture section and select the appropriate version e.g. 4.2
4) Scroll down to Deployment Section and also set “OS Deployment Target” as 4.2
5) Close the xCode Project (do not close the xCode Program) then reopen the Project

This solution came partly from a member of the iPhone SDK Development Forum and a little tweaking by me.

If this did not fix the problem then follow the steps in solution two, as follows:
Sometimes, if the test file has been created in a very old xCode Program,  you need to take more steps.
A solution for this problem was solved by a member of the “Leaves Developers” Google Group.

Solution Two
1) In xCode go to Targets and right click over the file name and select “Get Info”

Target Get Info Drop Down Menu

2) A drop down list will appear. Go to the Architecture section and click on the Base SDK Value field and select the correct iOS.

Target Architecture Drop Down Menu

3) Close the xCode Project (do not close the x Code program) and reopen the project.  Hopefully you will then see that the Base SDK Missing message has disappeared and you are seeing “Simulator …

Simulator Button on the xCode Dashboard

Xcode Development

NSTableView class to create a single column table view

1. Create an Xcode project

  • Step 01: Launch Xcode 3.0 and create a new project by clicking on File ⇒ New Project.
  • Step 02: Select Application ⇒ Cocoa Application and click on the Next button.
  • Step 03: Specify the Project Name and Project Directory as follows:
  • Project Name: SingleColumnTableView
  • Project Directory: ~/Documents/Project/XCode/Tutorial/SingleColumnTableView/
  • Click on the Finish button.

This will bring up the Project window.

2. Edit the NIB file

  • Step 01: In the Groups & Files browser, expand the NIB Files folder and double click the MainMenu.nib file.

This will launch the Interface Builder application and open the following windows:

  • a. Interface Builder NIB file browser
  • b. Interface Builder Inspector
  • c. Interface Builder Library
  • d. Application Main Menu window
  • e. Application Window

3. Create a controller class

  • Step 01: Use Xcode to create the application controller class. In the Groups & Files browser, right click on the Classes folder ⇒ Add ⇒ New File.
  • Step 02: Select Cocoa ⇒ Objective-C class and click on the Next button.

Specify a name for the application controller class and click on the Finish button.

  • Filename: ApplicationController.m

You should now be able to see the files for the ApplicationController class will be automatically added to the Xcode project.

Double click on the ApplicationController.h file to view its interface specifications.

Double click on the ApplicationController.m file to view its implementation details.

  • Step 03: Click on the Interface Builder icon to bring it to the foreground. Using the Interface Builder Library, select Objects & Controllers ⇒ Controllers ⇒ NSObject and drag it to the Interface Builder NIB file browser.

Using the Interface Builder Inspector, specify the following information:

  • Class Identity ⇒ Class: ApplicationController
  • Interface Builder Identify ⇒ Name: ApplicationController

Because Interface Builder is automatically synchronized with Xcode, you can see the ApplicationController class that was previously created in Xcode, in the drop-down list box for the class identify.

You should now be able to see the reference to the ApplicationController class in the NIB file browser as shown below.

  • Step 04: Specify an action that the application controller class can respond to.

Go to Class Actions, click on the button and specify an action called update:

  • Step 05: Specify an outlet that will be used by the application controller class to communicate with the target table view object.

Go to Class Outlets, click on the button and specify an outlet called tableView.

Leave the tableView type as id for the moment. The tableView type will be changed to NSTableView later on.

4. Create a table view and link it to the application controller class’ outlet

  • Step 01: Using the Interface Builder Library, click on the Objects tab and select the Views & Cells ⇒ Data Views folderr
  • Step 02: Drag and drop an NSTableView object from the library to the application window. Resize the NSTableView object so that it is correctly positioned within the window. Leave a little space at the bottom of the window, so that we can later on, add a button to update the table view contents.
  • Step 03: Since we’re going to create a single column table view, we will need to delete the second table column using the Interface Builder NIB file browser.

Expand the Window (Window) object till you reach the Table View node.

Select the second Table Column and delete the object using the menu option Edit ⇒ Delete.

Your application window should now contain a single column table view.

  • Step 04: Slowly click on the NSTableView object twice, to select the Table View object.

The first click will select the Scroll View object and the second click will select the Table View object. The Table View will be highlighted as shown below.

Ctrl+drag from the Table View object to the ApplicationController class to specify its dataSource and delegate outlets.

Right click on the Table View object to check the newly created associations for its dataSource and delegate outlets.

  • Step 05: Select the ApplicationController class and ctrl+drag to the Table View object to its tableView outlet.

Right click on the ApplicationController class to check the newly create association for the tableView outlet.

Using the Interface Builder, change the type for the tableView outlet to NSTableView.

5. Create a button and link it to the application controller class’ update action

  • Step 01: Using the Interface Builder Library, click on the Objects tab and select the Views & Cells ⇒ Buttons folder.
  • Step 02: Drag and drop an NSButton from the library to the application window.

Select the button and click on it once to rename it to Update.

  • Step 03: Select the Update button and ctrl+drag to the ApplicationController class in the Interface Builder NIB file browser.

Right click on the ApplicationController class to check the newly create association for the update: action.

6. Automatically generate source code and merge changes for the ApplicationController class

  • Step 01: Select the ApplicationController in the Interface Builder NIB file browser and click on File ⇒ Write Class Files.

Browse to the folder: ~/Documents/Project/XCode/Tutorial/SingleColumnTableView
Click on Save.
Click on Merge. This will launch the FileMerge utility.

  • Step 02: Merge changes to the ApplicationController.h file.

Select the ApplicationController.h file using the FileMerge utility.
This will show the ApplicationController.h source code differences between the

  • a. new source code that we just automatically generated using Interface Builder, on the left hand side
  • b. previous source code that we had initially generated using Xcode, on the right hand side
  • Difference #1: Select the first difference by pressing the ↓ down arrow key. We want to keep the changes on the right side so, press the → right arrow key. Alternatively, you can use the Actions drop down list to choose the difference to be selected for inclusion in the final merge.
  • Difference#2: Select the difference on the left, since we don’t want the extra line break.
  • Difference#3: Select the difference on the left, since we want the IBOutlet NSTableView *tableView; entry to be included in the final merge.
  • Difference#4: Select the difference on the left, since we want the – (IBAction)update:(id)sender; entry to be included in the final merge.

Save the merge by clicking on File ⇒ Save Merge. You should see a green tick mark next to the ApplicationController.h file.

  • Step 03: Merge changes to the ApplicationController.m file.

Select the ApplicationController.m file using the FileMerge utility.

This will show the ApplicationController.m source code differences between the

  • a. new source code that we just automatically generated using Interface Builder, on the left hand side
  • b. previous source code that we had initially generated using Xcode, on the right hand side
  • Difference #1: Select the difference on the right.
  • Difference#2: Select the difference on the left, since we don’t want the extra line break.
  • Difference#3: Select the difference on the left, since we want the – (IBAction)update:(id)sender; entry to be included in the final merge.

Save the merge by clicking on File ⇒ Save Merge. You should see a green tick mark next to the ApplicationController.m file.

Combine the files by selecting Merge ⇒ Combine Files.

Open the ApplicationController.h file to view the merged changes.

Open the ApplicationController.m file to view the merged changes.

7. Add a data source for the table view

  • Step 01: Open the ApplicationController.h file and add a data source.

Add the following lines of code just after the interface declaration:

  • // Data source
  • @private NSMutableArray *aBuffer;

8. Implement NSTableView protocol methods for displaying table view contents

  • Step 01: Implement the protocol method to retrieve the total number of rows in a table view.

Add the following lines of code to the ApplicationController.m file:

  • – (int)numberOfRowsInTableView:(NSTableView *)tableView{
  • return ([aBuffer count]);
  • }
  • Step 02: Implement the protocol method to retrieve the object value for a table column.

Add the following lines of code to the ApplicationController.m file:

  • – (id)tableView:(NSTableView *)tableView
  • objectValueForTableColumn:(NSTableColumn *)tableColumn
  • row:(int)row{
  • return [aBuffer objectAtIndex:row];
  • }

9. Implement the Update button handler

  • Step 01: Implement the ApplicationController update: method to print a log message to a console window and add a string object to the table view.

Add the following lines of code to the update: method in the ApplicationController.m file:

  • – (IBAction)update:(id)sender {
  • NSLog(@”The user has clicked the update button”);
  • [aBuffer addObject:@”HelloWorld”];
  • [tableView reloadData];
  • }

10. Implement the awakeFromNib and dealloc methods

  • Step 01: In the awakeFromNib method, implement code to create and allocate memory for a new mutable array object.

Add the following lines of code to the ApplicationController.m file:

  • – (void)awakeFromNib{
  • aBuffer = [NSMutableArray new];
  • [tableView reloadData];
  • }
  • Step 02: In the dealloc method, implement code to release memory allocated to the mutable array object.

Add the following lines of code to the ApplicationController.m file:

  • – (void)dealloc{
  • [aBuffer release];
  • [super dealloc];
  • }

11. Build and run the application

  • Step 01: Display the Xcode console window by clicking on Run ⇒ Console.
  • Step 02: In the Xcode project window, click on the Build and Go icon to build and launch the application.
  • Step 03: Click on the Update button. This will create a row entry in the table view.

View the resulting log messages on the console window.

Document version: 1.0
Document date: 2008-03-08
Document reference: XCT_NSTVSC-1.0


Development tools: Xcode 3.0, Interface Builder 3.0.
Operating system: Mac OS X 10.5.2 (Leopard)

Handling button events

1. Create an Xcode project

  • Step 01: Launch Xcode 3.0 by clicking on the Xcode application icon.
  • Step 02: Click on File ⇒ New Project
  • Step 03: Select Application ⇒ Cocoa Application and click on the Next button.
  • Step 04: Specify the Project Name and Project Directory as follows:

Project Name: HandlingButtonEvents
Project Directory: ~/Documents/Project/XCode/Tutorial/HandlingButtonEvents/

Click on the Finish button.

This will bring up the Project window.

2. Edit the NIB file

  • Step 01: In the Groups & Files browser, expand the NIB Files folder and double click the MainMenu.nib file

This will launch the Interface Builder application.

The Interface Builder (IB) application will display a set of windows for developing a Human Machine Interface (HMI):

  • a. Interface Builder NIB file browser
  • b. Interface Builder Inspector

c. Interface Builder Library
d. Application Main Menu window
e. Application Window

3. Create a controller class

  • Step 01: We will now use Xcode to create the application controller class. In the Groups & Files browser, right click on the Classes folder ⇒ Add ⇒ New File.
  • Step 02: Select Cocoa ⇒ Objective-C class and click on the Next button.

Specify a name for the application controller class and click on the Finish button.

Filename: ApplicationController.m

You should now be able to see the files for the ApplicationController class will be automatically added to the Xcode project.
Double click on the ApplicationController.h file to view its interface specifications.

Double click on the ApplicationController.m file to view its implementation details.

  • Step 03: Click on the Interface Builder icon to bring it to the foreground. Using the Interface Builder Library, select Objects & Controllers ⇒ Controllers ⇒ NSObject and drag it to the Interface Builder NIB file browser.

Using the Interface Builder Inspector, specify the following information:

Class Identity ⇒ Class: ApplicationController
Interface Builder Identify ⇒ Name: ApplicationController

Because Interface Builder is automatically synchronized with Xcode, you can see the ApplicationController class that was previously created in Xcode, in the drop-down list box for the class identify.

You should now be able to see the reference to the ApplicationController class in the NIB file browser as shown below.

  • Step 04: Specify an action that the application controller class can respond to.

Click on the button and specify an action called update:

Using Interface Builder, click on File ⇒ Write Class Files to to update the source files for the application controller class.

Click on the Save button.

Click on the Replace button to overwrite the existing application controller class files.

Double click on the ApplicationController.h file from the Xcode project browser window.

Observe the newly added action method entry in the interface file

  • – (IBAction)update:(id)sender;

Double click on the ApplicationController.m file from the Xcode project browser window.

Observe the newly added action method implementation entry in the implementation file

  • – (IBAction)update:(id)sender {
  • }
  • Step 05: Implement the update action method for the application controller class.

As an example, add code to the ApplicationController.m implementation file to print a debug log message to a console window.

  • – (IBAction)update:(id)sender {
  • NSLog(@”The user has clicked the update button”);
  • }

4. Create a button and link it to the application controller class’ update action

  • Step 01: Using the Interface Builder Library, click on the Objects tab and select the Views & Cells folder.
  • Step 02: Drag and drop an NSButton from the library to the application window.

Select the button and click on it once to rename it to Update.

  • Step 03: Select the Update button and ctrl+drag to the ApplicationController class in the Interface Builder NIB file browser.

Select the update: in the Recieved Actions pop-up window.

Select the Update button and view the button connections using the Interface Builder Inspector.

Select the ApplicationController class from the Interface Builder NIB file browser and view the application controller class connections.

5. Build and run the application

  • Step 01: Display the Xcode console window by clicking on Run ⇒ Console

This will bring up the Xcode console window.

  • Step 02: In the Xcode project window, click on the Build and Go icon to build and launch the application.

This will launch the application window.

  • Step 03: Click on the Update button.

View the resulting log messages on the console window.

Keyboard Shortcuts

  1. Alt-⌘-Up to alter between .m and .h file
  2. ⌘-Shift-D, When you want to open a file or a symbol definition that’s in your project or in a framework.
  3. ⌘-Shift-E expand the editor view to full height of the window.
  4. Alt-⌘-Left / Alt-⌘-Right, Navigate among open files back and forth.
  5. Press Tab to accept the current completion.
  6. Escape presents a pop-up list from which you can select from all the available completions (i.e after dot press Escape to list down a complete list).
  7. Control-comma to show the list of available completions, Control-period to insert the most likely completion, and Control-Slash & Shift-Control-Slash to move between place holder tokens.
  8. ⌘-double click on a symbol to see the definition of a symbol.
  9. Option-double click on a symbol to see the documentation for that symbol– OR– Right click on any word and select ‘Find Selected Text in API Reference’ to search the API for that word.
  10. Cmd-/ to automatically insert “//” for comments.
  11. Ctrl+Left/Right Arrow to do intra-word text navigation.
  12. Control-1 list down all the project files.
  13. Control-2 to access the popup list of functions/methods/symbols in this file.
  14. Control-3 list down all the include files
  15. Right click on a variable in your function and click edit all in scope (Best one).
  16. ⌘-[ and ⌘-] to indent and unindent selected text. Makes cleaning up source code much easier.
  17. Double-click on the square brackets or parentheses to obtain bracket and parentheses matching.
  18. Control-Shift-R to show the Console
  19. Control-Alt-⌘-R to clear the log
  20. Control-⌘ Left/Right to fold and unfold the function.
  21. Shift-⌘-C, the class browser in Xcode.
  22. ⌘-=, Jump to the next error in the list of build errors. Display the multiple Find panel with ⌘-Shift-F.
  23. ⌘-O, Jump to the Project tab, to the build tab with ⌘-Shift-B and to the debug tab with ⌘-Shift-Y.