我试图在
objective-c中编写我的第一个类,我想在类的方法中传递NSString对象作为参数,但是我得到一个错误,说“不能使用对象作为方法的参数”.所以我的问题是如何将字符串作为参数传递给方法?这是我的代码我试图开始工作:
#import <Foundation/Foundation.h> @interface Car { NSString *color; NSString *make; int year; } - (void) print; - (void) setColor: (NSString) c; - (void) setMake: (NSString) m; - (void) setYear: (int) y; @end @implementation Car - (void) print { NSLog(@"The $d Ford %@ is $@.",year,make,color); } - (void) setColor: (NSString) c { color=c; } - (void) setMake: (NSString) m { make=m; } - (void) setYear: (int) y { year=y; } @end int main (int argc,const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Car *car= [Car new]; [car setColor:@"blue"]; [car setMake:@"Bronco"]; [car setYear:1992] [car print]; [car release]; [pool drain]; return 0; }