IOS/Objective-C: Class接口错误中的方法
IOS/Objective-C: Class Method in Interface Error
我从一个没有导致错误的教程中复制了以下内容到我的项目中,它在指示的行上导致了三个错误。 (错误似乎不正确,因为当我尝试修复它们时,会出现其他错误。)任何人都可以提出可能是什么问题:
@interface VC ()
NSDictionary(JSONCategories) //MULTIPLE ERRORS THIS LINE including cannot declare variables inside @interface
+(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString*)urlAddress;
-(NSData*)toJSON;
@end
这是一个 NSDictionary
类别;你想要:
@interface NSDictionary(JSONCategories)
+(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString*)urlAddress;
-(NSData*)toJSON;
@end
我假设您正在尝试创建一个类别:
a category interface looks exactly like a normal interface, except the
class name is followed by the category name in parentheses.
例如类别应声明为:
#import "Car.h"
@interface Car (Maintenance) //Maintainence is a category
- (BOOL)needsOilChange;
- (void)changeOil;
- (void)rotateTires;
- (void)jumpBatteryUsingCar:(Car *)anotherCar;
@end
我从一个没有导致错误的教程中复制了以下内容到我的项目中,它在指示的行上导致了三个错误。 (错误似乎不正确,因为当我尝试修复它们时,会出现其他错误。)任何人都可以提出可能是什么问题:
@interface VC ()
NSDictionary(JSONCategories) //MULTIPLE ERRORS THIS LINE including cannot declare variables inside @interface
+(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString*)urlAddress;
-(NSData*)toJSON;
@end
这是一个 NSDictionary
类别;你想要:
@interface NSDictionary(JSONCategories)
+(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString*)urlAddress;
-(NSData*)toJSON;
@end
我假设您正在尝试创建一个类别:
a category interface looks exactly like a normal interface, except the class name is followed by the category name in parentheses.
例如类别应声明为:
#import "Car.h"
@interface Car (Maintenance) //Maintainence is a category
- (BOOL)needsOilChange;
- (void)changeOil;
- (void)rotateTires;
- (void)jumpBatteryUsingCar:(Car *)anotherCar;
@end