0

I'm trying to create a preprocessor macro to simplify a bit of code that I'm continually using. The code just creates a dictionary and then posts a notification. Like so:

NSDictionary* dict = [NSDictionary dictionaryWithObject:@"This is a test"
                                                 forKey:@"debugMessage"];

[[NSNotificationCenter defaultCenter] postNotificationName:@"FLRDebugViewLog"
                                                    object:self
                                                  userInfo:dict];

I'd love to create a macro so that I could just type:

MBDebug(@"This is a test",self);

i.e. just passing in the message and object I want to post. How would I accomplish this?

2
  • Any reason why you want a macro over a regular C function? Commented Jul 12, 2012 at 23:57
  • I hadn't even considered a c function. I guess the only reason I was thinking macro was because I'm just expanding text, essentially, so a compile time macro seemed like it'd be most efficient. Commented Jul 14, 2012 at 13:32

1 Answer 1

2

This should work. :)

#define MBDebug(m,s) NSDictionary* dict = [NSDictionary dictionaryWithObject:m forKey:@"debugMessage"]; [[NSNotificationCenter defaultCenter] postNotificationName:@"FLRDebugViewLog" object:s userInfo:dict];
Sign up to request clarification or add additional context in comments.

1 Comment

Wow, I guess I should have figured that out myself. Thanks!

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.