Search code examples
iosobjective-cclass-method

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

Solution

  • This is an NSDictionary category; you want:

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

    Apple Reference.