user1904273
user1904273

Reputation: 4764

IOS/Objective-C: Class Method in Interface Error

I copied the following from a tutorial where it did not cause an error into my project where it causes three errors on the line indicated. (The errors don't seem correct as when I try to fix them, other errors occur.) Can anyone suggest what might be problem:

@interface VC ()
   NSDictionary(JSONCategories) //MULTIPLE ERRORS THIS LINE including cannot declare variables inside @interface
+(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString*)urlAddress;
-(NSData*)toJSON;
@end

Upvotes: 0

Views: 98

Answers (2)

Teja Nandamuri
Teja Nandamuri

Reputation: 11201

I assume you are trying to create a category:

a category interface looks exactly like a normal interface, except the class name is followed by the category name in parentheses.

For example Categories should be declared as:

#import "Car.h"

@interface Car (Maintenance)   //Maintainence is a category

- (BOOL)needsOilChange;
- (void)changeOil;
- (void)rotateTires;
- (void)jumpBatteryUsingCar:(Car *)anotherCar;

@end

Upvotes: 3

l00phole
l00phole

Reputation: 632

This is an NSDictionary category; you want:

@interface NSDictionary(JSONCategories)
+(NSDictionary*)dictionaryWithContentsOfJSONURLString:(NSString*)urlAddress;
-(NSData*)toJSON;
@end

Apple Reference.

Upvotes: 3

Related Questions