Todd Davies
Todd Davies

Reputation: 5522

iOS error: No visible @interface for 'Project' 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?

Upvotes: 12

Views: 14414

Answers (2)

erkanyildiz
erkanyildiz

Reputation: 13224

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

Upvotes: 7

Amy Worrall
Amy Worrall

Reputation: 16337

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.

Upvotes: 34

Related Questions