12

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

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

这是项目类的代码:

项目.h

#import <Foundation/Foundation.h>

@interface Project : NSObject
{

}

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

@end

项目.m

#import "Project.h"

@implementation Project

    @synthesize projectID, name;

@end

No visible @interface for 'Project' declares the selector 'alloc' 尝试初始化对象时出现错误。我该如何解决这个问题?

4

2 回答 2

34

您似乎正在尝试调用与类完全相同的变量:Project *Project。难怪编译器会感到困惑!

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

于 2012-08-14T09:21:28.580 回答
7

永远不要使用类名作为实例引用名。

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

GoddamnClass *anInstanceOfGoddamnClass = [GoddamnClass new]; // works like a magic
于 2012-08-14T09:27:36.033 回答