Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 719
Todd Davies Avatar asked Aug 14 '12 09:08

Todd Davies


2 Answers

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.

like image 55
Amy Worrall Avatar answered Sep 30 '22 22:09

Amy Worrall


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
like image 27
erkanyildiz Avatar answered Sep 30 '22 22:09

erkanyildiz