Archive for June, 2010

[iOS] setter getter

Wednesday, June 9th, 2010

SetterGetterTest

SetterGetterTest.h

#import 


@interface SetterGetterTest : NSObject {
	int x;
	NSString *name;
}
- (void)setX:(int)value;
- (void)setName:(NSString *)value;
- (int)x;
- (NSString *)name;

@end

SetterGetterTest.m


#import "SetterGetterTest.h"

@implementation SetterGetterTest

- (void)setX:(int)value
{
	x = value;
}

- (void)setName:(NSString *)value
{
	name = value;
}

- (int)x
{
	return x;
}

- (NSString *)name
{
	return name;
}
@end

usage


#import 
#import "SetterGetterTest.h"

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    SetterGetterTest *sgt = [[SetterGetterTest alloc] init];
	sgt.x = 5;
    NSLog(@"x is %d, name is %@", sgt.x, sgt.name);
	
	sgt.name = @"bar";
	NSLog(@"x is %d, name is %@", sgt.x, sgt.name);
	
    [pool drain];
    return 0;
}

[iOS] struct, typedef, enum

Wednesday, June 9th, 2010

struct

#import 

struct coordinate {
	int x;
	int y;
};

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	struct coordinate myc;
	myc.x = 10;
	myc.y = 5;
	
	NSLog(@"x is %d, y is %d", myc.x, myc.y);
    
    [pool drain];
    return 0;
}

typedef

It is changed the method that declare the variable.

#import 

typedef struct{
	int x;
	int y;
} coordinate;

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	//change how to declare variable 
	coordinate myc;
	myc.x = 7;
	myc.y = 11;
	
	NSLog(@"x is %d, y is %d", myc.x, myc.y);
    
    [pool drain];
    return 0;
}

enum

#import 

enum personalDataType {
	NAME = 1,
	PHONE,
	ADDRESS
};

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	NSLog(@"NAME %d, PHONE %d, ADDRESS %d", NAME, PHONE, ADDRESS);
    
    [pool drain];
    return 0;
}

use typedef keyword


#import 

typedef enum{
	NAME = 0,
	PHONE,
	ADDRESS
} personData;

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	personData pd;
	pd = PHONE;
	NSLog(@"pd is %d", pd);
    
    [pool drain];
    return 0;
}

[iOS] Multiview Applications

Monday, June 7th, 2010

I had bought the book that is named “Beginning iPhone 3 Development: Exploring the iPhone SDK”.

Now I try to learn the iPhone development in English only not Japanease.
It is too difficult for me.
But I have challenged.

Today’s learning iPhone development result is Multiview Applications in Chapter6.
I have not understood the relationship UIVIew and Controller well yet.
I will continue to learning.