在.m文件中设置一个类实例,没有在每个方法中这样实现,而是在全部方法:
-(void)viewDidLoad
{
Class *c = [Class new];
}
在.h文件中:
@interface RandomViewController : UIViewController
{
Class *c [Class new];
}
运行之后报错:
Expected ';' at end of declaration list
在.m文件中设置一个类实例,没有在每个方法中这样实现,而是在全部方法:
-(void)viewDidLoad
{
Class *c = [Class new];
}
在.h文件中:
@interface RandomViewController : UIViewController
{
Class *c [Class new];
}
运行之后报错:
Expected ';' at end of declaration list
ChatGPT尝试为您解答,仅供参考
在.h文件中声明类实例时,你需要指定它的类型,但是在这里你没有这样做。
你应该改为:
@interface RandomViewController : UIViewController
{
Class *c;
}
或者,你也可以在.h文件中使用@property声明类实例:
@interface RandomViewController : UIViewController
@property (nonatomic, strong) Class *c;
然后在.m文件的viewDidLoad方法中初始化它:
-(void)viewDidLoad
{
self.c = [Class new];
}
这样就可以避免在.h文件中声明类实例的错误了。