Hello - I declared a class which has an NSString object as instance variable. As an excercise, I would like to create an instance of the class and set the variable, but I am completely unable to do it.
This is the horrible code I wrote... (Started Obj C yesterday night...

).
Code:
#import <Foundation/Foundation.h>
@interface Person : NSObject
{
NSString *person;
}
-(void) SetPersonName : (NSString *) name;
//-(NSString) GetPersonName;
@end
@implementation Person
-(void) SetPersonName : (NSString*) name;
{
person = &name;
}
@end
int main (int argc, const char * argv[])
{
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
Person testperson;
testperson = [Person alloc];
testperson = [testperson init];
NSString nametogive = @"Louis Armstrong";
[testperson SetPersonName =nametogive];
[pool drain];
return 0;
}
I get the following errors:
Quote:
pollux@desktop:~/Desktop$ gcc `gnustep-config --objc-flags` -lgnustep-base stringtest.m -o eloisa
stringtest.m: In function ‘-[Person SetPersonName:]’:
stringtest.m:14: warning: assignment from incompatible pointer type
stringtest.m: In function ‘main’:
stringtest.m:22: error: statically allocated instance of Objective-C class ‘Person’
stringtest.m:22: error: statically allocated instance of Objective-C class ‘Person’
stringtest.m:23: error: incompatible types when assigning to type ‘struct Person’ from type ‘id’
stringtest.m:24: error: cannot convert to a pointer type
stringtest.m:24: error: incompatible types when assigning to type ‘struct Person’ from type ‘id’
stringtest.m:26: error: invalid initializer
stringtest.m:26: error: statically allocated instance of Objective-C class ‘NSString’
stringtest.m:26: error: statically allocated instance of Objective-C class ‘NSString’
stringtest.m:27: error: expected ‘]’ before ‘=’ token
stringtest.m:27: warning: ‘Person’ may not respond to ‘-SetPersonName’
stringtest.m:27: warning: (Messages without a matching method signature
stringtest.m:27: warning: will be assumed to return ‘id’ and accept
stringtest.m:27: warning: ‘...’ as arguments.)
stringtest.m:27: error: cannot convert to a pointer type
stringtest.m:26: warning: unused variable ‘nametogive’
|
It's quite obvious I am doing something wrong!
Thanks!