How to put a combination of characters as a permanent command in the iOS framework

I am new to iOS programming. I am currently developing some SDK framework. I have a command with three characters: "ESC" 'E' '1', I want to combine these three characters to create an NSString and put this NSString in the framework. Therefore, others can directly use this constant within the framework.

Does anyone know how to do this? Since in constant.h file you cannot use any runtime functions like StringWithFormat.

I am also thinking about using \ u to combine three characters. like this: NSString * message2 = @ "\\ u001b \\ u002d \\ u0031"; but it failed. It counts as such a long string: \\ u001b \\ u002d \\ u0031, not ESC + E + 1

Many thanks.

+3


source to share


1 answer


\u

wildcards are limited by the ISO 10646 standard to exclude certain characters. ESC is of particular interest to you. But you can encode it in octal:

NSString *message2 = @"\033E1";

      

Note that you usually don't put them in a header file. You usually implement it like this:

MYMessages.h



// Declare it here
extern NSString * const MYMessage2;

      

MYMessages.m

// Define it here
NSString * const MYMessage2 = @"...";

      

Avoid generic files like constant.h

. Place your constants in the header that most closely matches. For example, NSGlobalDomain

is a string constant defined in NSUserDefaults.h

because it is used with custom defaults. There is no global file "CocoaStringConstants.h".

+1


source







All Articles