Secrets of launch arguments (iOS)

Secrets of launch arguments (iOS)

Tips of launch arguments for iOS development.

9bf923e39671cde83584e3e926296c13?s=128

Kishikawa Katsumi

January 15, 2014
Tweet

Transcript

  1. 4FDSFUTPGMBVODIBSHVNFOUT J04

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

    * argv[]) { @autoreleasepool { return UIApplicationMain( argc, argv, nil, NSStringFromClass([AppDelegate class])); } }
  4. int main(int argc, char * argv[]) w BSHDDPOUBJOTUIFOVNCFSPGBSHVNFOUT w BSHWJTBBSSBZPGBSHVNFOUT

  5. 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
  6. /41SPDFTT*OGP

  7. - (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 )
  8. /46TFS%FGBVMUT

  9. $POWFOUJPOT LFZWBMVFLFZ5XPXPSE w BLFZTUBSUTXJUI w 2VPUFWBMVFTJGNPSFUIBOPOFXPSET

  10. None
  11. - (void)viewDidLoad { [super viewDidLoad]; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

    NSLog(@"%@", [userDefaults stringForKey:@"foo"]); NSLog(@"%@", [userDefaults stringForKey:@"baz"]); } => bar qux quux
  12. None
  13. - (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
  14. $BOQBTTNPSFDPNQMFY EBUBUZQFT

  15. "SSBZ BSSBZ"SH GPP CBS CB[ 

  16. None
  17. - (void)viewDidLoad { [super viewDidLoad]; NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

    NSLog(@"%@", [userDefaults objectForKey:@"arrayArg"]); } => ( foo, bar, baz )
  18. %JDUJPOBSZ EJDU"SH\GPPCBSCB[RVY^ => { baz = qux; foo = bar;

    }
  19. 1MJTUGPSNBU \GPPCBSCB[RVY^  GPP CBS CB[  "SSBZ %JDUJPOBSZ

  20. .PSFDPNQMFYFYBNQMF QMJTU"SH\GPPCBSBSSBZ GPP \CBSCB[^ ^ => { array = (

    foo, { bar = baz; } ); foo = bar; }
  21. 9.-QMJTUGPSNBU YNM"SHlEJDULFZGPPLFZTUSJOHCBS TUSJOHLFZCB[LFZTUSJOHRVYTUSJOHEJDU => { baz = qux; foo =

    bar; }
  22. 5IFNBHJDUSJDLPG b"QQMF-BOHVBHFT FT ` IUUQOTIJQTUFSDPNMBVODIBSHVNFOUTBOEFOWJSPONFOUWBSJBCMFT

  23. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSLog(@"%@", [userDefaults dictionaryRepresentation]); => {

    ... ! AppleLanguages = ( ja, en, fr, ... ); ! ... ! }
  24. NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults]; NSLog(@"%@", [userDefaults dictionaryRepresentation]); => {

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