iOS error: No visible @interface for 'xxxx' declares the selector 'alloc'


I am initialising an object like so:

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

Here's the code for the project class:

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

I'm getting the error No visible @interface for 'Project' declares the selector 'alloc' when I try and initialise the object. How can I resolve this?

share | improve this question
 

2 Answers

up vote 14 down vote accepted

You seem to be trying to call a variable the exact same name as the class: Project *Project. It's no wonder the compiler is getting confused!

Switch the variable name to lower case, Project *project.

share | improve this answer
 
5  
What an idiot I am... :P –   Todd Davies  Aug 14 '12 at 9:22 
 
Happens to everybody at least once... At least... For my sake, I hope it does :D –   Daij-Djan  May 29 at 14:48

Never use the class name as an instance reference name.

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

GoddamnClass *anInstanceOfGoddamnClass = [GoddamnClass new]; // works like a magic
share | improve this answer

I am initialising an object like so:

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

Here's the code for the project class:

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

I'm getting the error No visible @interface for 'Project' declares the selector 'alloc' when I try and initialise the object. How can I resolve this?

share | improve this question
 

2 Answers

up vote 14 down vote accepted

You seem to be trying to call a variable the exact same name as the class: Project *Project. It's no wonder the compiler is getting confused!

Switch the variable name to lower case, Project *project.

share | improve this answer
 
5  
What an idiot I am... :P –   Todd Davies  Aug 14 '12 at 9:22 
 
Happens to everybody at least once... At least... For my sake, I hope it does :D –   Daij-Djan  May 29 at 14:48

Never use the class name as an instance reference name.

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

GoddamnClass *anInstanceOfGoddamnClass = [GoddamnClass new]; // works like a magic
share | improve this answer
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值