Hello,
I'm new to writing in Objective-C (as of yesterday) and am for the first time practicing writing classes. I've got this bit of code...
This works fine, displaying what i'd expect. My question is - if I wanted to add a string value to my class, say "Firstname" - how do I go about adding that? I've tried using NSString - but unsure of the format. I expect my book will cover this eventually, but i'm already attempting to write things before that point.
Any help is gratefully received.
JT
I'm new to writing in Objective-C (as of yesterday) and am for the first time practicing writing classes. I've got this bit of code...
Code:
#import <Foundation/Foundation.h>
@interface Person : NSObject
{
int age;
}
- (void) setAge: (int) age;
- (void) showit;
@end // end of Person (interface)
@implementation Person
- (void) setAge: (int) a
{
age = a;
}
- (void) showit
{
NSLog (@"The age for this person is %d", age);
}
@end // end of Person (implementation)
int main (int argc, const char * argv[]) {
id test[1];
test[0] = [Person new];
[test[0] setAge: 25];
[test[0] showit];
return 0;
}
This works fine, displaying what i'd expect. My question is - if I wanted to add a string value to my class, say "Firstname" - how do I go about adding that? I've tried using NSString - but unsure of the format. I expect my book will cover this eventually, but i'm already attempting to write things before that point.
Any help is gratefully received.
JT