iOS错误:'Project'没有可见的@interface声明选择器'alloc'

时间:2012-08-14 09:19:04

标签: iphone objective-c ios

我正在初始化一个像这样的对象:

Project *Project = [[Project alloc] init];

这是项目类的代码:

Project.h

#import <Foundation/Foundation.h>

@interface Project : NSObject
{

}

    @property (nonatomic,assign) int projectID; 
    @property (nonatomic,strong) NSString *name; 

@end

Project.m

#import "Project.h"

@implementation Project

    @synthesize projectID, name;

@end

我在尝试初始化对象时收到错误 No visible @interface for 'Project' declares the selector 'alloc' 我该如何解决此问题?

2 个答案:

答案 0 :(得分:32)

您似乎试图将变量调用与类完全相同的名称:Project *Project。难怪编译器感到困惑!

将变量名称切换为小写Project *project

答案 1 :(得分:6)

绝不要将类名用作实例引用名称。

GoddamnClass *GoddamnClass = [GoddamnClass new]; // will have problems

GoddamnClass *anInstanceOfGoddamnClass = [GoddamnClass new]; // works like a magic