Created
November 3, 2009 21:00
-
-
Save sukima/225417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
@interface Person : NSObject { | |
NSString *screenName; | |
NSString *realName; | |
NSURL *imageURL; | |
} | |
@property (nonatomic, retain) NSString *screenName; | |
@property (nonatomic, retain) NSString *realName; | |
@property (nonatomic, retain) NSURL *imageURL; | |
- (id)initWithScreenName:(NSString *)sn | |
realName:(NSString *)rn | |
imageURLString:(NSString *)imageUrlStr; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "Person.h" | |
@implementation Person | |
@synthesize screenName; | |
@synthesize realName; | |
@synthesize imageURL; | |
- (id)initWithScreenName:(NSString *)sn | |
realName:(NSString *)rn | |
imageURLString:(NSString *)imageUrlStr; | |
{ | |
if ( (self = [super init]) == nil) | |
return nil; | |
self.screenName = sn; | |
self.realName = rn; | |
NSURL *url = [[NSURL alloc] initWithString:imageUrlStr]; | |
self.imageURL = url; | |
[url release]; | |
return self; | |
} | |
- (void)dealloc; | |
{ | |
[super dealloc]; | |
[screenName release]; | |
[realName release]; | |
[imageURL release]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Foundation/Foundation.h> | |
#import "Person.h" | |
int main(void) | |
{ | |
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; | |
NSMutableArray *array = [[NSMutableArray alloc] init]; | |
[array autorelease]; | |
Person *p1 = [[Person alloc] initWithScreenName:@"dude1" | |
realName:@"Joe Dude" imageURLString:@"http://somewhere.com/dude1.jpg"]; | |
Person *p2 = [[Person alloc] initWithScreenName:@"dude2" | |
realName:@"John Dude" imageURLString:@"http://somewhere.com/dude2.jpg"]; | |
Person *p3 = [[Person alloc] initWithScreenName:@"dudette3" | |
realName:@"Jane Dudette" imageURLString:@"http://somewhere.com/dudette3.jpg"]; | |
[array addObject:p1]; | |
[array addObject:p2]; | |
[array addObject:p3]; | |
[p1 release]; | |
[p2 release]; | |
[p3 release]; | |
Person *object = [array objectAtIndex:1]; | |
NSLog(@"The second object in the array is %@", object.realName); | |
[pool release]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment