Chapter 6 : Introducing Objective-C and Xcode

This forum contains all the assignments and questions readers may have for each chapter.

Moderator: gary.bennett

Chapter 6 : Introducing Objective-C and Xcode

Postby gary.bennett » Sat Aug 14, 2010 3:33 pm

Introducing Objective-C and Xcode
    Creating an Objective-C Class
    Declaring Interfaces and Instance Variables
    Sending Messages (Methods)
    Working with the Implementation File
    Implementing Methods
    Using Our New Class
    Overriding Default Behavior
    Taking Class Methods to the Next Level
    Accessing the Xcode Documentation

Weekly Q&A for Objective-C for Absolute Beginners Book

Purpose: Answer questions about Objective-C and OOP from book or other related info.
This Webinar is held every week on Wednesday, from:
6:30 PM - 7:30 PM PST
Register Now at:
Once registered you will receive an email confirming your registration with information you need to join the Webinar.
System Requirements
PC-based attendees
Required: Windows® 7, Vista, XP or 2003 Server
Macintosh®-based attendees
Required: Mac OS® X 10.4.11 (Tiger®) or newer
Ch06 -
Chapter 6
(26.04 KiB) Downloaded 382 times
User avatar
Posts: 564
Joined: Thu Feb 26, 2009 3:12 pm

Re: Chapter 6 : Introducing Objective-C and Xcode

Postby jshapiro » Tue Dec 06, 2011 6:45 pm

Is this what´s expected to happen with the exercise 6

[Switching to process 2121]
2011-12-06 19:44:19.484 MyFirstApp[2121:1307] Hello World!
2011-12-06 19:44:19.534 MyFirstApp[2121:1307] Hola mundo!

Debugger stopped.
Program exited with status value:0.
Posts: 10
Joined: Tue May 17, 2011 2:54 pm

Chapter 6 Introducing Objective C and Xcode

Postby Marcolavida » Fri Dec 16, 2011 7:50 am

Im in a programming class and part of our assignements is we have to generate our own makefiles. Does anybody know how I can prevent Xcode from generating the makefile for me and instead instead write my own for my C program?


Le consejo una tienda online donde todos pueden comprar Levitra en Espana sin gastos de envio. A veces algunos suelen conseguir Sildenafilo en Espana con rebajas.
Posts: 0
Joined: Wed Nov 30, 2011 11:34 pm

Re: Chapter 6 : Introducing Objective-C and Xcode

Postby stockholm » Sat May 12, 2012 3:30 am

Hi Gary!
I managed to extend the program "My First App" in chapter 6 to also include a Reset button that erases the resulting lines of text
so the buttons can be pushed again and again without closing the App...
Since I'm a total newbie to code - in any form - I'm both excited and scared! ; ) Sometimes I seem to get the hang of it,
sometimes It is really hard to follow. It's a rollercoaster, but I've promised myself to follow through.
I think the hardest is to understand and translate the meaning of each line and what each sign relates to, I wish every example of code was chopped up into every
little detail and explained further. Here's an example where I'm lost on some of the details.

The beginning of the original code in the example (chapter 6) has following lines:

#import "HelloWorldViewController.h"

@implementation HelloWorldViewController

- (IBAction)showName:(id)sender {
[nameLabel setText:@"My Name is Stockholm..."]; //OK here I changed the message text, but it can be anything you wish of course.


I changed the code, added two buttons in the .xib file and realized I could erase the line ":(id)sender"
in all code (both in the .m and .h file) and still get it to work properly:


#import <UIKit/UIKit.h>

@interface HelloWorldViewController : UIViewController {
IBOutlet UILabel *nameLabel;
IBOutlet UILabel *messageLabel;

-(IBAction) showName;
-(IBAction) showMessage;
-(IBAction) clear; //I implemented a clear function here to be able to "erase" the messages created in "showName" and "showMessage"




#import "HelloWorldViewController.h"

@implementation HelloWorldViewController

- (IBAction)showName {
[nameLabel setText:@"My name is stockholm..."];

- (IBAction)showMessage {
[messageLabel setText: @"...and I'm trying hard to learn code!"];
- (IBAction)clear {
[nameLabel setText:@""];
[messageLabel setText:@""]; // These commands replaces the textfields with "nothing"

Now my question: What is ":(id)sender"? Why is it there in the original code?
How come it works well without it?

Also I realize my reset button is maybe a bit fake (?) as it actually change the value to
"no visible text", maybe there's a more correct command to use when resetting the values to zero/null?
How would you write it in order to get back to the state it was in before any button was pushed?

Thank you for a great book/website/forum/webinars!
Posts: 0
Joined: Fri May 11, 2012 5:16 am

Re: Chapter 6 : Introducing Objective-C and Xcode

Postby lightsquared » Sat Aug 18, 2012 2:29 pm

When will the the video be uploaded for Chapter 6?

Posts: 1
Joined: Fri Jun 15, 2012 6:11 pm

Re: Chapter 6 : Introducing Objective-C and Xcode

Postby adominus » Fri Dec 13, 2013 6:20 am

Hello ,
i am e-learning with this book.
Its complicated but it is to do.

when i trey to create MyFirstApp,
i didn't get a file with *.xib, like MainWindow.xib or ViewController.xib.
i am using Xcode 5.0.2

perhaps its chains in this version in " Main.storyboard" ?

does anybody now?

kind regards
Posts: 0
Joined: Mon Dec 02, 2013 3:28 am

Re: Chapter 6 : Introducing Objective-C and Xcode

Postby Drago » Sat Jun 07, 2014 12:46 pm

Chapter 6 - Final Exercise
- If you feel you have the hang of this, add a new button and label both to the ViewController object and to the interface. Change it from displaying your name to displaying something else.

I'm using OS X 10.9.3 and Xcode 5.1.1

Code: Select all
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController{
    IBOutlet UILabel *nameLabel;
    IBOutlet UILabel *greetingLabel;

- (IBAction)showName:(id)sender;
- (IBAction)showGreeting:(id)sender;


Code: Select all
#import "ViewController.h"

@interface ViewController ()


@implementation ViewController

- (void)viewDidLoad
    [super viewDidLoad];
   // Do any additional setup after loading the view, typically from a nib.

- (void)didReceiveMemoryWarning
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.

- (IBAction)showName:(id)sender
    [nameLabel setText:@"My name is anakata!"];

- (IBAction)showGreeting:(id)sender
    [greetingLabel setText:@"Hello! ana!"];

Main.storyboard [screenshot]
"It's more fun to be a pirate than to join the navy."
Steve Jobs.
User avatar
Posts: 0
Joined: Thu Jun 20, 2013 3:41 pm

Return to Book -> Objective-C for Absolute Beginners: (2nd Edition) iPhone and Mac Programming Made Easy