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

2

12

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?

Zacatecas answered 14/8, 2012 at 9:19 Comment(0)
A
34

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.

Apostasy answered 14/8, 2012 at 9:21 Comment(2)
Happens to everybody at least once... At least... For my sake, I hope it does :DHornblende
you saved few moments of hair pulling on my head :-PCoddle
S
7

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
Sedda answered 14/8, 2012 at 9:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.