0

I'm trying to define string literal Name in command line and use it in my code, for example NSLog("%@", Name);. I'm referring to this post and trying to convert it to clang/objective-c format.

In my makefile:

clang -DName=$(printf "%s-%d" $(ls $(PWD)/.folderA/folderB | sort -V | tail -n 1) $(cat $(PWD)/folderA/folderB/$(ls $(PWD)/.folderA/folderB | sort -V | tail -n 1)))

and in my code:

#define STRINGIZE(x) #x
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
NSLog(@"%@", [NSString stringWithUTF8String:STRINGIZE_VALUE_OF(Name)]);

However, the logged output is empty. But if I try much more simpler command like

clang -DName=$(PWD)

it does logged correctly. Any idea why?

Ryan
  • 67
  • 6
  • Hi - that should work. Just note, since that is a C string, you can log it directly using ```NSLog( @"%s", ...```) in stead of converting it and logging it with ```NSLog( @"%@", ...```. But that should work, I think the problem lies inside the ```$(printf ...```. – skaak Oct 19 '20 at 04:10
  • Looking at the inside, I think you have a ```.folder``` that should be just ```folder```. – skaak Oct 19 '20 at 04:12
  • `.folder` is a hidden folder, that's why its prefixed by `.` – Ryan Oct 19 '20 at 04:38
  • Ok sure, still I think the trouble is there somewhere. – skaak Oct 19 '20 at 04:39

0 Answers0