Cocoa Development

... an introduction

by Lieven Dekeyser

Part 1

What is Cocoa

Cocoa on Mac OS X

Mac OS X Layers

Cocoa on Mac OS X

Mac OS X Dependencies

Cocoa on iPhone OS

Mac OS X Layers

Objective-C

C: Hello World

#include <stdio.h>

int main(int argc, const char * argv[])
{
    printf("hello world");
    return 0;
}

C: Hello World, explained

C: Types

C: Pointers

C: Pointers

C: Pointer gotchas

C: Strings

C: Memory allocation

Objective-C

Objective-C: Class interface

@interface Circle : NSObject
{
    float mX;
    float mY;
    float mRadius;
}

- (id)init;
- (id)initWithRadius:(float)inRadius x:(float)inX y:(float)inY;

- (float)surface;

@end

Objective-C: Class implementation

@implementation Circle

- (id)init
{
	return [self initWithRadius:0.0f x:0.0f y:0.0f];
}

- (id)initWithRadius:(float)inRadius x:(float)inX y:(float)inY
{
	self = [super init];
	if (self != nil)
	{
		mX = inX;
		mY = inY;
		mRadius = inRadius;
	}
	return self;
}

- (float)surface
{
	return M_PI * mRadius * mRadius;
}

@end

Objective-C: Instances & messages

#import "Circle.h"

int main(int inNumArgs, const char * inArgs[])
{
    Circle * circle = [[Circle alloc] initWithRadius:100.0f
        x:10.0f y:5.0f];
       
    float surface = [circle surface];
    
    NSLog(@"Circle surface = %.2f", surface);
    
    return 0;
}

Objective-C: Memory management

Objective-C: Autorelease Pools

The End

Questions?