I am currently working through the Big Nerd Ranch iPhone book, and am fooling around with different tableView projects. In one of these, I created a separate class to contain a series of strings. These will be used in a navigation controller, to be inputted in text fields in a detail view. In my class I made it simple, having my class start with only one string. I was getting an error when I ran the project, so I figured this class I created had a problem. So I tried to use it in a simple objective-c project. The code is listed below. The output of this should be "jimmy". Instead I get the following --
"2010-10-14 12:00:27.561 ClassTest[8552:a0f] <Name: 0x10010c760>"
Any help is appreciated. Thanks.
Adam
"2010-10-14 12:00:27.561 ClassTest[8552:a0f] <Name: 0x10010c760>"
Code:
#import <Foundation/Foundation.h>
@interface Name : NSObject
{
NSString *_first;
}
@property (nonatomic, retain) NSString *first;
+ (id)nameWithFirst:(NSString *)first;
- (id)initWithFirst:(NSString *)first;
@end
#import "Name.h"
@implementation Name
@synthesize first = _first;
- (void)dealloc
{
[_first release];
[super dealloc];
}
+ (id)nameWithFirst:(NSString *)first
{
Name *name = [[self alloc] initWithFirst:first];
return [name autorelease];
}
- (id)init
{
return [self initWithFirst:@""];
}
- (id)initWithFirst:(NSString *)first
{
self = [super init];
[self setFirst:first];
return self;
}
+(id)someName
{
Name*newName=[[self alloc]initWithFirst:@"jimmy"];
return newName;
}
@end
#import <Foundation/Foundation.h>
#import "Name.h"
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
NSLog(@"%@",[Name someName]);
[pool drain];
return 0;
}
Any help is appreciated. Thanks.
Adam