Skip to main content
added 55 characters in body
Source Link
Yam
  • 803
  • 9
  • 19

Inspired by NSMutableString idea from Chris, I make a perfect macro imho. It supports insert nil elements without any Exceptions.

#import <libextobjc/metamacros.h> #define STR_CONCAT(...) \ ({ \ __auto_type str__ = [NSMutableString string]; \ metamacro_foreach_cxt(never_use_immediately_str_concatify_,, str__, __VA_ARGS__) \ (NSString *)str__.copy; \ }) #define never_use_immediately_str_concatify_(INDEX, CONTEXT, VAR) \ [CONTEXT appendString:VAR ?: @""]; 

Example:

STR_CONCAT(@"button_bg_", @(count).stringValue, @".png"); // button_bg_2.png 

If you like, you can use id type as parameter by using [VAR description] instead of NSString.

Inspired by NSMutableString idea from Chris, I make a perfect macro imho.

#import <libextobjc/metamacros.h> #define STR_CONCAT(...) \ ({ \ __auto_type str__ = [NSMutableString string]; \ metamacro_foreach_cxt(never_use_immediately_str_concatify_,, str__, __VA_ARGS__) \ (NSString *)str__.copy; \ }) #define never_use_immediately_str_concatify_(INDEX, CONTEXT, VAR) \ [CONTEXT appendString:VAR ?: @""]; 

Example:

STR_CONCAT(@"button_bg_", @(count).stringValue, @".png"); // button_bg_2.png 

If you like, you can use id type as parameter by using [VAR description] instead of NSString.

Inspired by NSMutableString idea from Chris, I make a perfect macro imho. It supports insert nil elements without any Exceptions.

#import <libextobjc/metamacros.h> #define STR_CONCAT(...) \ ({ \ __auto_type str__ = [NSMutableString string]; \ metamacro_foreach_cxt(never_use_immediately_str_concatify_,, str__, __VA_ARGS__) \ (NSString *)str__.copy; \ }) #define never_use_immediately_str_concatify_(INDEX, CONTEXT, VAR) \ [CONTEXT appendString:VAR ?: @""]; 

Example:

STR_CONCAT(@"button_bg_", @(count).stringValue, @".png"); // button_bg_2.png 

If you like, you can use id type as parameter by using [VAR description] instead of NSString.

Source Link
Yam
  • 803
  • 9
  • 19

Inspired by NSMutableString idea from Chris, I make a perfect macro imho.

#import <libextobjc/metamacros.h> #define STR_CONCAT(...) \ ({ \ __auto_type str__ = [NSMutableString string]; \ metamacro_foreach_cxt(never_use_immediately_str_concatify_,, str__, __VA_ARGS__) \ (NSString *)str__.copy; \ }) #define never_use_immediately_str_concatify_(INDEX, CONTEXT, VAR) \ [CONTEXT appendString:VAR ?: @""]; 

Example:

STR_CONCAT(@"button_bg_", @(count).stringValue, @".png"); // button_bg_2.png 

If you like, you can use id type as parameter by using [VAR description] instead of NSString.