I am working on a command-line tool which would run the method
- [NSMutableDictionary setObject:(id)object forKey:(NSString *)key]
The value I want to pass as object is the the content of the string argv[4]… So the user would type:
mytool arg1 arg2 arg3 [NSString stringWithFormat:@"asd"]
Still, plain argv[4] is obviously a char*, so I can’t add that as an object.
Is there a way to turn that string with an object as its content in a plain object so I can pass it on the method above?
Being: Turn "[NSString stringWithFormat:@"asd"]" into [NSString stringWithFormat:@"asd"]?
Note: This applies to any Objective-C object, so I could also pass as argv[4] something like [NSArray arrayWithObjects:@"obj1", nil].
Thanks in advance.
Here’s a brief example of converting C strings into classes and selectors at runtime.
That’s a simple example with three tokens:
NSString,stringWithFormat:, and one argument. To handle more complicated cases, you need to write your own string parser. It shows you some possibilities, though.