Showing posts with label Tips. Show all posts
Showing posts with label Tips. Show all posts

Mac Tips and Tricks

Get all Mac OS X Tips, Tricks, Tutorials, Hacks, Support, Downloads, Updates...right in to your Mac OS X Mountain Lion, Lion, Snow Leopard, Leopard or Tiger Dashboard !
Learn How To using Finder, Preview, iChat, iCal, Mail, Safari, Address Book, Expose, Dock, Dashboard, Spotlight, Keyboard Shortcuts...or Customizing Your Mac !
↓ Download

Moving from Xcode 3 to Xcode 4

The majority of changes that will affect you for Xcode 4 are related to a redesigned user interface. This post offers a general overview of these differences, including hidden panels and integrated Interface Builder.

Overall Interface Redesign
Perhaps the most obvious change is that everything is now unified into a single-window interface.

When you first open a project in Xcode 4 (or create a new one), you’ll notice a lack of items in the lefthand portion (which under Xcode 3 would be the Groups & Files list). For the TextApp project from the first chapter of the book, you’ll find only a single item listed, with an Xcode project icon:

Expand this to see the files within it, and click a file to open it in the editor:

Because Xcode 4 is designed primarily so that everything occurs within a single window (it is still possible to double-click a file to open it in a separate window), many features are “hidden” behind panels and navigator controls.

The left portion of the main window contains Navigators, each of which is used to navigate through different aspects of a project—use the little icon buttons to choose which one. Since you’ll find yourself swapping between navigators fairly frequently, it’s worth pointing out that the icons correspond to the options in the View > Navigators menu, so each has a prominent keyboard shortcut.

If you’re relatively new to coding, or even just to Xcode, it’s easy to become confused as to why you’re not seeing what you think you should be seeing in this navigator pane. To see the list of groups and files, you need the Project Navigator (Cmd-1).

Debugger Console
The Debugger Console (a separate window under Xcode 3) has also been moved into the main interface, and the default keyboard shortcut has changed. You’ll need to use the segmented control labelled View in the main toolbar of the Xcode window to display the “bottom bar.”

This lower panel is known as the Debug Area in Xcode 4, and can also be hidden/shown from the View menu (Shift-Cmd-Y). The Debug Area has several purposes; it’s also used instead of another, separate Debugger window in Xcode 3. Depending on which you need (it’s the Console area on the right for this book), you can choose whether to show both panels or just one using the segmented control that appears in the lower panel of the window:

The default behavior in Xcode 4 is to hide the debug area each time you run an application. If you wish, you can change this—choose Xcode > Preferences… (Cmd-,) and select the Behaviors tab, then set what happens when a Run starts to Show the Debug Area automatically each time:

Note that if you’re particularly attached to any default Xcode 3 keyboard shortcuts, it’s possible to change the Xcode 4 shortcuts using the Key Bindings tab in the Preferences window.

Separate Windows
If you don’t like having everything arranged on the one window, Xcode 4 can open as many extra windows as you like. Double-clicking any file, for example, will open that file in a new window. Working with multiple windows can get confusing, though, particularly when it comes to closing the project. Skip this section if you’re still relatively new to Xcode in any version.

Once you have a new window open, you decide how much you want it to display. If you particularly want a separate debugger console window, for example, choose File > New > New Window (Shift-Cmd-T). By default, a new window opened in this way will display the same information as the previous front-most window. If this is the first new window you’ve opened for a project, you’ll effectively get two identical Xcode project windows. Use the new window’s main toolbar to turn off the left and right bars, and display the bottom bar, then drag the bottom bar up to fill the window:

Once you’ve done that, you can hide the main toolbar itself by clicking the button in the top right of the window’s title bar:

Xcode 4 will remember the window locations and layout when you close the project, but make sure you use File > Close Project to do so (by default this doesn’t have a keyboard shortcut, but you can add one in the Preferences window—in the Key Bindings panel, the command is listed as Close Workspace).

If you instead try to close the project by closing what looks to you like the main project window, the project will still be open, but with only the shrunk console window on display. If you then close this window as well (at which point Xcode will close the project because that’s the last open window), then all you’ll see when you next open the project will be the console window. The first time this happened to me, I had a minor panic trying to figure out how to get back to my original window. If this happens to you, just calmly re-display the main toolbar, and open the left, Navigators area. Hide the bottom bar, and you’ll be back to a normal “project window.”

Execution Controls
To match the iTunes-like single-window interface, the Xcode 3 Build and Run/Stop buttons have been replaced in Xcode 4 with simple Run and Stop buttons in the main toolbar:


The default shortcuts for Building (Cmd-B), Running (Cmd-R), and Cleaning (Shift-Cmd-K) remain the same under Xcode 4—the menu commands are found under the Product menu.

In the middle of the toolbar is a status area, again much like iTunes, to indicate what’s going on. If a Build fails with errors or generates warnings, these are indicated in this area.

Notice also that if errors or warnings are generated, these are displayed in the Issue Navigator pane on the left, which will appear automatically if issues are found. This Issue Navigator (Cmd-4) replaces the separate Build Results window under Xcode 3. As before, errors and warnings are displayed as overlays on top of the relevant code:

And, as mentioned earlier, when you want to get back to the list of files in the project you’ll need to switch to the Project Navigator pane (Cmd-1).

Editors
Xcode 4 has a variety of editor “modes,” including an Assistant editor. Any time you open a file when using the Assistant, Xcode 4 will also display what it thinks is the most closely-related file (such as the class interface header file for a class implementation).

Switch to the Assistant by using the Editor segmented control in the main toolbar, or choose View > Editor > Assistant (Opt-Cmd-Return):

Health Warning: Use of Xcode 4 may cause extreme desire for a larger monitor/display

If you prefer viewing just one file at a time, you can use the Related Files popup menu to jump between counterparts, and even superclasses, protocol definitions, etc:

Note that the default shortcut to display the counterpart file (i.e., jump from an implementation file to an interface file), has changed from Opt-Cmd-UpArrow to Ctrl-Cmd-UpArrow. Take a look at the list of Jump commands in the Navigate menu for a full list of helpful shortcuts.

The third editor, the Version editor, is used for projects under a source code Version Control System, e.g. Git or Subversion. Versioning isn’t something covered in the book, but it’s a great addition to Xcode for when you start using a system like Git.

Integrated Interface Builder
Interface Builder used to be a separate application, which would communicate behind the scenes with the Xcode 3 environment to make sure relevant code changes were represented in the interface. There were a few gotchas with this, including the need to save .xib or .nib files in Interface Builder before Building and Running in Xcode.

Under Xcode 4, the entire interface-editing environment has been integrated into the Xcode application itself.

When you click a .xib file, it will open in the editor:

The left hand side of this editor pane contains the icons representing the objects within the .xib file. If you click the window icon, the window will appear in the pane:

The blue box surrounding the window in the graph paper area includes a Close button to hide the window from the editor; if you need to show lots of objects in the editor pane, you can drag the blue box containers to rearrange items.

Inspectors
The object inspectors are no longer found under separate panels in Xcode 4; instead, you’ll need to use the main toolbar View segmented control to display the “right bar,” or Utilities area:

The top half of this Utilities area contains Inspector panels. Just like Navigators on the left of the window, you use the little icon buttons to swap between the different inspectors, which also have corresponding menu items and keyboard shortcuts:



Libraries
The lower half of the Utilities area is used for Libraries. Again, use the little icon buttons to switch between them (or use the menu options shown above). For interface editing, you’ll need the Object Library (Ctrl-Opt-Cmd-3):



Making Connections
IBOutlet and IBAction connections are made in the same way as they were in the standalone Interface Builder.

If you’re making a connection from one of several objects in the left-hand column of the Interface Editing panel, hover over any icon to show its class name:


Right-click (or Ctrl-click) to show the available connections, and click-drag out from the circle to make the connection:

Under Xcode 4, there’s also another connection option available if you use the Assistant Editor.

The Assistant Editor will display the class interface that it thinks is most closely related to the objects in a .xib file; for the TextApp application, this will likely be the TextAppAppDelegate.h file. Given that the connections you’ll need to make in the book are initially for the NotifyingClass object, you’ll need to use the Assistant’s file dropdown to choose one of the other related files, NotifyingClass.h:

Once you’ve done this, Xcode 4 allows you to make connections directly to the IBAction and IBOutlet entries in the code file:


You’ll need to hover over the code until the words “Connect Action” or “Connect Outlet” appear; if you hover in an empty area, or between lines, Xcode 4 will insert an action or outlet automatically at the code location where you release the mouse button.

If you hover in one place for two long, Xcode 4 may “drill down” into the code, and show you superclass interfaces, etc. If this happens, either use the file dropdown mentioned above, or the back/forward buttons at the top left of the assistant’s code file panel:



Project Template Changes
The templates seem to change with every minor revision of Xcode. For Xcode 4 onwards, you’ll find the organization of the project is slightly different from that shown in the book for Xcode 3. You should find that the files still have the same names, but the Classes group now has the name of your application, and the various resources and other sources are now found either inside this group or inside its Supporting Files group.

The code that’s included in the project templates has also changed a little. You’ll find that any provided init method, which used to look like this:

- (id)init
{
    if (self = [super init]) {
        // Initialization code here.
    }
   
    return self;
}


now looks like this:

- (id)init
{
    self = [super init];
   
    if (self) {
        // Initialization code here.
    }
   
    return self;
}


One change in Xcode 4 that may cause confusion is that you’ll now get a warning if you use the first style—you’ll now get a warning any time you use an assignment inside a conditional if() statement. If you are particularly attached to using this style, you’ll need to add an additional set of parentheses to silence the warning:

- (id)init
{
    if ((self = [super init])) {
        // Initialization code here.
    }
   
    return self;
}

Objective-C with Xcode

Creating a project
To create a Hello World application with Objective-C, first open Xcode (if you don't have it, you must install the Developer Tools included with Mac OS X). Choose File > New Project... and choose "Cocoa Application" (in the Application section) as the project type. Choose an appropriate project name and location and click "Finish".


The interface
When your project is created, a number of files are created, but you don't need to use most of them. Your next step is to design the interface, which is done in Interface Builder. Double click on the "MainMenu.nib" file in the "Groups & Files" list.

When the file opens in Interface Builder, several windows will open. The first, titled "MainMenu.nib", is the file itself, which can store many different objects. Another is "Window", which by default will be displayed when you run the application. This window is the same as the "Window" object in the "MainMenu.nib" window. Finally, there may be one or two floating windows such as palettes and the inspector.


Designing your interface
Your task is to create a "Hello World" message. In the floating palettes window (choose Tools > Palettes > Show Palettes if it is not visible), select the Text palette (the third from the left). Several possible controls will be displayed here, which you can add to your window by dragging them. Drag a text field (or as called in Cocoa, an NSTextField) to your window, preferably the one titled "System Font Text".

You may notice when you drag a control over your window that blue dotted lines appear. These are called Aqua Guidelines, and are used to help you decide where to place controls so that your interface conforms to human interface guidelines. Position your text field in the top left of your window so that it snaps to both horizontal and vertical guidelines.

You should now change the text of your text field. Double click it and type in "Hello World!" Finally, you should resize your window to a more compact size. Do this by resizing a window how you normally would, with the drag box at the bottom right. Now save your interface, close the "MainMenu.nib" window and return to Xcode.


Building your application
One of the advantages of using Cocoa is that many things can be done without using any code. This is one of those occasions. Additionally, although it may seem like it's been a lot of work to do such a simple task, you'll find when you run your application that a lot of features have been added for you.

To compile and execute your application, click the "Build and Go" button in Xcode's toolbar. When it's finished, your application will run and the Hello World message will appear.

Now you have a chance to see all the features that have automatically been added to your application. Viewing each menu will give you some idea. These features include an about window, window resizing, search tools, spell checking, printing and more. This is a huge advantage to using Objective-C and Cocoa that many other languages do not have.


Using Objective-C with Console I/O
While it is useful to be able to display fixed text using Interface Builder, it can also be useful to explore building a "Hello World" application with Objective-C without the use of Aqua. Since few support files will be needed, open an empty project; in Xcode, choose File > New Project... and choose "Empty Project" as the project type. Then click "Next", name your project, and click "Finish". An empty project will be created.

Now that you have a project, you must create a source file. Choose File > New File... and choose "Empty File in Project" from the dialog. Name the file "main.m", and click "Finish". The file will be added to your project. Double click main.m if it did not open automatically, and enter the following:

 #import <Cocoa/Cocoa.h>
 
 @interface World:NSObject
 {
 }
 -world;
 @end
 
 @implementation World
 - world
 {
     NSLog(@"Hello World!");
     return 0;
 }
 @end
 
 int main(int argc, char *argv[])
 {
     id hello;
 
     hello=[[World alloc] init];
     [hello world];
     
     return 0;    
 }


Save this file, then choose Project > New Target... and choose Cocoa > Application as the target type. Click "Next", name the target, and click "Finish".

In the project window, expand the "Targets" menu in the left pane, then expand the target you just chose. Drag "main.m" from the right pane to "Compile Sources" under your target.

Finally, you must add the Cocoa framework to your project, as it is used in the source code. To do this, click the Action pop up button in the toolbar of the project window and choose Add > Existing Frameworks.... Navigate to and select /System/Library/Frameworks/Cocoa.framework.

You can now run the application by choosing Build > Build and Run.



C++ (with Xcode)
Apple includes "Hello World!" as the default source file when creating a "C++ tool" project in Xcode. To see this, choose File > New Project... then choose "C++ Tool" (in the "Command Line Utility" section) as the project type. Click "Next", choose an appropriate project name and location, then click "Finish". In the main window, labeled with the name of the project you chose, double-click "main.cpp" to open the C++ source. At this point you can observe the following code (as of Xcode 2.3):

 #include <iostream>
 
 int main (int argc, char * const argv[]) {
     // insert code here...
     std::cout << "Hello, World!\n";
     return 0;
 }


You can modify this code to change its behaviour, but the existing code will compile and run, printing "Hello World!" and a line break in the console, then exiting with a return code of 0. You can click "Build and Go" in the main.cpp window or main project window to compile and run the program.


Java
The Hello World application for Java is below. The file name must be HelloWorld.java because of the class name so it can be run properly. This code can be typed and saved in any text editor that will save plain text files.

public class HelloWorld{
    public static void main(String[] args){
        System.out.println("Hello World");
    }
}



This code can be compiled in Terminal using these commands:

javac HelloWorld.java
java HelloWorld




AppleScript
Creating a Hello World application with AppleScript is much simpler than most languages. First, you must open Script Editor (or other AppleScript compiler), located at /Applications/AppleScript/Script Editor.

You should then type in the following code in a script window:

display dialog "Hello World!"

Click the run button to see the message in action.

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 <MobileCoreServices/UTCoreTypes.h>

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.

<?xml version="1.0"?> <note>
<to>Steve</to> <from>Paul</from> <message>Have a good weekend!</message>
</note>



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.

Improve iPhone Battery Life

Some of our readers had noticed significant decrease in battery life after upgrading to iOS 4.3.
Users are reporting that the issue is fixed after disabling Ping, Apple’s social network for music. So if you’ve noticed decrease in battery life after upgrading to iOS 4.3 then you can try to disable Ping to see if it helps.

You can disable Ping by following these simple steps:
-Launch the Settings app.
-Tap General, then Restrictions.
-Tap Enable Restrictions.
-Enter the passcode, which is required to enable restrictions (and to access it later).
Please make sure it's something you can remember. 
-Toggle Ping to Off.
You can try this out if you’ve noticed a similar issue on your iPad and iPod Touch after upgrading to iOS 4.3.

Take a Picture of your iPhone screen

It is so easy!
Press and hold the Home button, then press the Sleep/Wake button. Your screen flashes and the picture of your screen appears in your Camera Roll.

Create web clips.



To add a website to your Home screen, visit the page in Safari and tap the Go To icon at the bottom of the Safari window.
Tap Add to Home Screen.

Cut, copy, and paste.

Find the text you want to edit in a note, email, web page, or other app. You can select a word by double-tapping it, and select more or less text by dragging the grab points. Then tap to cut, copy, or paste. To undo an edit, shake iPhone, then tap the Undo button.

Double Tap Shift for Caps Lock

Many people don’t like caps lock, but it’s still available on your iPhone if you so wish. You will have to enable it, though. “Settings > General > Keyboard > Enable Caps Lock” should do the trick. Then, just double-tap the shift key to type away in

Tap and Hold for Extra Characters

How would you type the British Pound symbol on your iPhone? Or an inverted question mark? And what about letters with cedillas? To get these, and other special characters, tap and hold on the letter or symbol that closest represents the one you want.
You’ll get a hidden menu that offers the extra characters. This also works with the .com button, offering a few other top-level domains.

Double Tap Shift for Caps Lock

Many people don’t like caps lock, but it’s still available on your iPhone if you so wish. You will have to enable it, though. “Settings > General > Keyboard > Enable Caps Lock” should do the trick. Then, just double-tap the shift key to type away in capitals.

Tap and Hold for Extra Characters

How would you type the British Pound symbol on your iPhone? Or an inverted question mark? And what about letters with cedillas? To get these, and other special characters, tap and hold on the letter or symbol that closest represents the one you want.
You’ll get a hidden menu that offers the extra characters. This also works with the .com button, offering a few other top-level domains.