2

For localization, I can define %@ in localized string and it will be populated dynamically.

But can I do same thing for this one? If I can't, is there any alternative way? I don't want to write function and call from there.

#define MESSAGE @"Event - %@ is now saved in your calender."
1

1 Answer 1

3

Macros are not dynamic. That means, that the compiler will write @"Event - %@ is now saved in your calender." everywhere you use MESSAGE.

But you can replace the %@ placeholder on runtime using stringWithFormat::

#define MESSAGE @"Event - %@ is now saved in your calender."
NSString *string = [NSString stringWithFormat:MESSAGE, @"EventName"];

string will now be: Event - EventName is now saved in your calender.

Sign up to request clarification or add additional context in comments.

1 Comment

I am looking for this one. Thanks you :)

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.