不能上新课

joh*_* cs -5 iphone xcode objective-c ios

每次我尝试创建一个新类时,我都会得到一堆错误,甚至没有编写一行代码.

register.h

#import <UIKit/UIKit.h>
@interface register : UIViewController
@end
Run Code Online (Sandbox Code Playgroud)

给出错误:

预期标识符
预期标识符或'('

register.m

#import "register.h"
@interface register ()
@end
@implementation register
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
Run Code Online (Sandbox Code Playgroud)

@implementation注册

预期标识符
预期标识符或'('

- (void)viewDidLoad- (void)didReceiveMemoryWarning给:

缺少方法声明的上下文

@end 得到:

@end必须出现在objective-c上下文中

每次我创建一个新类而不编写任何代码时都会发生这种情况.

Iow*_*a15 7

您不能使用保留关键字命名类,变量,函数等.以下是Objective-C关键字列表:http://cupsofcocoa.com/2010/09/09/reserved-keywords/

要解决您的问题,请为您的类命名,而不是注册(这不是保留关键字).你甚至可以命名它Register,它会编译.