2010-07-25 27 views
6

İlk sınıfımı objektif-c'ye yazmaya çalışıyorum ve sınıfın bir yönteminde bir parametre olarak bir NSString nesnesini iletmek istiyorum, ancak "bir nesneyi bir parametreye bir yöntem olarak kullanamaz" diyen bir hata alıyorum ". Yani sorum şu: Bir dizeyi bir yönteme nasıl parametre olarak geçiriyorsunuz? işte çalışmam için şu kodum işim:Bir dize nesnel-c'de bir yöntem parametresi olarak nasıl geçebilirim?

#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 [email protected]", 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; 
} 

cevap

15

Dize nesnesine bir işaretçi vermeniz gerekiyor. Yani,

f.e.

- (void) print; 
- (void) setColor:(NSString *) c; 
- (void) setMake:(NSString *) m; 
- (void) setYear:(int) y; 

ve tamamen işe yaradı uygulanması

+0

aynı, yardımlarınız i bir cevap web'de arama oldum ve bana cevap başarmış tek kişisin için çok teşekkürler . çok teşekkürler bir demet – Joe

İlgili konular