I want to create an macro for trimming my string.
I use this code below for trimming:
[[NSString stringWithString:string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]
But if I create macro as below I get an error: expected expression
#define TRIM_STRING(string) ([[NSString stringWithString:string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]])
How to correctly create same define macro?
As a macro:
However, there’s really no reason not to use an inline function here. You get type checking, and the compiler will give you error messages that make sense. The same as an inline function:
Or, even better, create a category on NSString for this:
This way you get namespacing, and you can call it by doing
which is neater and more consistent with Cocoa.