您的位置:首页 > 移动开发 > IOS开发

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

2013-10-14 23:30 633 查看





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

up
vote4down
votefavorite

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?

iphone objective-c ios
share|improve
this question
asked Aug 14 '12 at 9:19




Todd Davies
1,5241025

 


2 Answers

activeoldestvotes

up
vote14down
voteaccepted
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
answered Aug 14 '12 at 9:21




Amy Worrall
8,59711038

 
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
up
vote2down
vote
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
edited Au

up
vote4down
votefavorite

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?

iphone objective-c ios
share|improve
this question
asked Aug 14 '12 at 9:19




Todd Davies
1,5241025

 


2 Answers

activeoldestvotes

up
vote14down
voteaccepted
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
answered Aug 14 '12 at 9:21




Amy Worrall
8,59711038

 
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
up
vote2down
vote
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
edited Au

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: