本文介绍了iOS错误:“项目"没有可见的@interface声明选择器"alloc"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在初始化一个对象,像这样:

I am initialising an object like so:

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

这是项目类的代码:

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

我遇到错误 No visible @interface for 'Project' declares the selector 'alloc' 当我尝试初始化对象时.如何解决此问题?

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?

推荐答案

您似乎正在尝试调用与类完全相同的变量:Project *Project.难怪编译器会感到困惑!

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!

将变量名称切换为小写字母Project *project.

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

这篇关于iOS错误:“项目"没有可见的@interface声明选择器"alloc"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 07:42