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?

4
  • 3
    Did you put the hash (#) before define? Can you paste the output error? Commented Nov 26, 2013 at 0:38
  • Keep in mind that Objective-C is "C", it is a strict superset. Everything that works in "C" also works in Objective-C. Commented Nov 26, 2013 at 0:42
  • There's really no good reason to use a define rather than a const string for that purpose. Commented Nov 26, 2013 at 0: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? Commented Nov 29, 2013 at 2:06

1 Answer 1

5

The correct syntax for a define is:

#define VARIABLE @"value"
Sign up to request clarification or add additional context in comments.

2 Comments

Note: there is no equal sign.
Sorry the syntax is #define ENTITY_USER_PICTURE @"UserPicture" i wnat to use this as variable a parameter insertNewObjectForEntityForName

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.