0

I'm pretty new to Objective-C and what I want to do is have define variables in the EntityNameConstants.h file where I store all the Entity Names.

And the I will use all the defines in repository for all the methods related to the ManagedObjectContext.

EG. This is in the .h file

define ENTITY_USER_PICTURE = @"UserPicture"

and in repository i want to use this constants as following

UserPicture *userPicture = (UserPicture *)[NSEntityDescription insertNewObjectForEntityForName:ENTITY_USER_PICTURE
                                                                            inManagedObjectContext:context];

but I cannot do this, it gives me Parse Issue error.

Am I doing anything wrong in here?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Nikita255
  • 15
  • 5
  • 3
    Did you put the hash (#) before define? Can you paste the output error? – pasine Nov 26 '13 at 00:38
  • Keep in mind that Objective-C is "C", it is a strict superset. Everything that works in "C" also works in Objective-C. – zaph Nov 26 '13 at 00:42
  • There's really no good reason to use a define rather than a const string for that purpose. – Jesse Rusak Nov 26 '13 at 00:46
  • Hi the syntax for define is #define ENTITY_USER_PICTURE @"UserPicture". and Hi Jesse i see what you are saying but in that case for const i need .h and .m file where i have only .h file where i declare only #define. so i don't want to introduce new class for constants. is there any alternative? – Nikita255 Nov 29 '13 at 02:06

1 Answers1

5

The correct syntax for a define is:

#define VARIABLE @"value"
Holly
  • 5,270
  • 1
  • 24
  • 27