다음과 같은 목표 C 클래스가 있습니다.목표 C 클래스 초기화 오류
Film film = [[Film alloc] init];
나는 다음과 같은 오류를 얻을 : 가변 sizedobject가 초기화되지 않을 수 있습니다 나는이 클래스의 객체를 만들려고 할 때마다 그것은 영화 스타일 설정, 제목 장소의 ID 등의 영화에 대한 정보를 저장하는 것입니다 , Objective-C 클래스 "Film"의 정적으로 할당 된 인스턴스, Objective-C 클래스 "Film"의 인스턴스를 정적으로 할당.
저는 Objective C에 꽤 익숙하며 아마도 C# 사고 방식에 머물러 있습니다. 아무도 내가 뭘 잘못하고 있다고 말할 수 있습니까?
감사 마이클
코드 :
// Film.m
#import "Film.h"
static NSUInteger currentID = -1;
@implementation Film
@synthesize filmID, title, venueID;
-(id)init {
self = [super init];
if(self != nil) {
if (currentID == -1)
{
currentID = 1;
}
filmID = currentID;
currentID++;
title = [[NSString alloc] init];
venueID = 0;
}
return self;
}
-(void)dealloc {
[title release];
[super dealloc];
}
+(NSUInteger)getCurrentID {
return currentID;
}
+(void)setCurrentID:(NSUInteger)value {
if (currentID != value) {
currentID = value;
}
}
@end
// Film.h
#import <Foundation/Foundation.h>
@interface Film : NSObject {
NSUInteger filmID;
NSString *title;
NSUInteger venueID;
}
+ (NSUInteger)getCurrentID;
+ (void)setCurrentID:(NSUInteger)value;
@property (nonatomic) NSUInteger filmID;
@property (nonatomic, copy) NSString *title;
@property (nonatomic) NSUInteger venueID;
//Initializers
-(id)init;
@end
잘못된 형식에 대해 미안하지만 아직 여기 코드 블록을 만드는 방법을 알지 못합니다 –