Created
August 2, 2013 23:50
-
-
Save jeremy-w/6144348 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//cc -Wall -framework Foundation nsargs.m -o nsargs | |
/* @author Jeremy W. Sherman | |
* @date 2013-08-02 | |
* | |
* Demonstrates NSArgumentDomain. | |
* | |
* Try: | |
* ./nsargs -a YES -foo fishy -x 3 | |
* | |
* 2013-08-02 19:49:35.331 nsargs[48904:707] nsargs: command-line args: | |
* a <- YES (__NSCFConstantString) | |
* foo <- fishy (__NSCFString) | |
* x <- 3 (__NSCFConstantString) | |
*/ | |
#import <Foundation/Foundation.h> | |
int | |
main(void) | |
{ | |
NSDictionary *args = [[NSUserDefaults standardUserDefaults] | |
volatileDomainForName:NSArgumentDomain]; | |
NSMutableArray *items = [NSMutableArray new]; | |
for (NSString *key in args) { | |
id arg = args[key]; | |
NSString *item = [NSString stringWithFormat:@" %@ <- %@ (%@)", | |
key, arg, [arg class]]; | |
[items addObject:item]; | |
} | |
NSString *argsAlt = [items componentsJoinedByString:@"\n"]; | |
/* Note how they all come through as NSStrings. */ | |
NSLog(@"%@: command-line args:\n%@", | |
[NSProcessInfo processInfo].processName, argsAlt); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment