여기 내 코드입니다. 그것은 매우 간단하지만 오류를 내가 가진 여기objective-c 코드를 컴파일하는 중에 오류가 발생했습니다.
#import <Foundation/Foundation.h>
@interface Car: NSObject
@property(nonatomic,retain) NSString *brand;
@property int year;
@end //Car Interface
#import "Car.h"
@implementation Car
@synthesize brand, year;
@end //Car Implementation
#import "Car.h"
int main (int argc, const char * argv[])
{
int y;
//Creo un nuovo oggetto
Car *myCar = [[Car alloc] init];
//Setto i parametri
[myCar setBrand: @"BMW Z4"];
NSLog (@"Inserisci data modello: ");
scanf (" %i", &y); //E' buona norma lasciare uno spazio
[myCar setYear: y];
//Stampo a video i dati
NSLog(@"Marca: %@ Anno: %i", [myCar brand], [myCar year]);
return (0);
}
오류를 이해하지 않습니다
car.m:5:1: error: ivar 'brand' used by '@synthesize' declaration must be an existing iva
car.m:5:1: error: ivar 'year' used by '@synthesize' declaration must be an existing ivar
car.m:7:1: warning: incomplete implementation of class 'Car' [enabled by default]
car.m:7:1: warning: method definition for '-setBrand:' not found [enabled by default]
car.m:7:1: warning: method definition for '-brand' not found [enabled by default]
car.m:7:1: warning: method definition for '-setYear:' not found [enabled by default]
car.m:7:1: warning: method definition for '-year' not found [enabled by default]
이것은 이전 질문과 거의 동일합니다. http://stackoverflow.com/questions/17996426/any-mistakes-using-property-and-synthesize. 그것이 당신을 위해 작동하지 않는 이유는 무엇입니까? - 아마 당신은 ** GNUstep **을 사용하고 있음을 다시 언급해야합니다. –
네, 그 코드는 같지만 이전에 문제가 있었지만 그 오류는 더 이상 없습니다. 이제 문제는 다릅니다. – Mazzy
이것은 GNUstep과 관련이 없습니다. 나는 GNUstep과 함께 clang을 사용하고 있으며 코드를 잘 컴파일 할 수있다. –