Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Secrets of launch arguments (iOS)

Secrets of launch arguments (iOS)

Tips of launch arguments for iOS development.

Kishikawa Katsumi

January 15, 2014
Tweet

More Decks by Kishikawa Katsumi

Other Decks in Programming

Transcript

  1. #import <UIKit/UIKit.h> ! #import "AppDelegate.h" ! int main(int argc, char

    * argv[]) { @autoreleasepool { return UIApplicationMain( argc, argv, nil, NSStringFromClass([AppDelegate class])); } }
  2. int main(int argc, char * argv[]) { @autoreleasepool { for

    (int count = 0; count < argc; count++) { NSLog(@"argv[%d] = %s", count, argv[count]); } ! return UIApplicationMain( argc, argv, nil, NSStringFromClass([AppDelegate class])); } } => argv[0] = /Users/kishikawakatsumi/Library/Application Support/iPhone Simulator/7.0.3-64/Applications/ 55179656-7577-4C46-AE05-6D83E25EC2CD/Arguments.app/Arguments argv[1] = foo argv[2] = bar
  3. - (void)viewDidLoad { [super viewDidLoad]; NSProcessInfo *processInfo = [NSProcessInfo processInfo];

    ! NSLog(@"%@", processInfo.arguments); } => ( "/Users/kishikawakatsumi/Library/Application Support/iPhone Simulator/7.0.3-64/Applications/55179656-7577-4C46- AE05-6D83E25EC2CD/Arguments.app/Arguments", foo, bar )
  4. - (void)viewDidLoad { [super viewDidLoad]; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

    NSLog(@"%@", [userDefaults stringForKey:@"foo"]); NSLog(@"%@", [userDefaults stringForKey:@"baz"]); } => bar qux quux
  5. - (void)viewDidLoad { [super viewDidLoad]; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

    NSLog(@"%d", [userDefaults boolForKey:@"boolArg"]); NSLog(@"%d", [userDefaults integerForKey:@"intArg"]); NSLog(@"%f", [userDefaults floatForKey:@"floatArg"]); NSLog(@"%@", [userDefaults stringForKey:@"stringArg"]); } => 1 18 3.141590 foo bar
  6. - (void)viewDidLoad { [super viewDidLoad]; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

    NSLog(@"%@", [userDefaults objectForKey:@"arrayArg"]); } => ( foo, bar, baz )
  7. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSLog(@"%@", [userDefaults dictionaryRepresentation]); => {

    ... ! AppleLanguages = ( es ); ! ... ! } b"QQMF-BOHVBHFT FT `NFBOT PWFSSJEJOH/46TFS%FGBVMUTUFNQPSBSJMZ  b FT `JTBSSBZPGMBOHVBHFDPEFT