Advertisement
zxlk21e

namescontroller

May 21st, 2012
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.04 KB | None | 0 0
  1. //
  2. // SecondViewController.m
  3. // BabyNamesGeneratorPro
  4. //
  5.  
  6. #import "SecondViewController.h"
  7.  
  8. @interface SecondViewController ()
  9.  
  10. @end
  11.  
  12. @implementation SecondViewController
  13. @synthesize saveName;
  14. @synthesize babyname;
  15. @synthesize generateGName;
  16.  
  17. - (void)viewDidLoad
  18. {
  19. [super viewDidLoad];
  20. // Do any additional setup after loading the view, typically from a nib.
  21. }
  22.  
  23. - (void)viewDidUnload
  24. {
  25. [self setSaveName:nil];
  26. [self setBabyname:nil];
  27. [self setGenerateGName:nil];
  28. [super viewDidUnload];
  29. // Release any retained subviews of the main view.
  30. }
  31.  
  32. - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
  33. {
  34. return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
  35. }
  36. - (IBAction)generateGName:(id)sender {
  37. int a = arc4random() % 49;
  38. int b = arc4random() % 49;
  39.  
  40.  
  41. // populate the array for the names
  42. NSArray *firstNameArray = [NSArray arrayWithObjects: @"Isabella",
  43. @"Sophia",
  44. @"Emma",
  45. @"Olivia",
  46. @"Ava",
  47. @"Emily",
  48. @"Abigail",
  49. @"Madison",
  50. @"Chloe",
  51. @"Mia",
  52. @"Addison",
  53. @"Elizabeth",
  54. @"Ella",
  55. @"Natalie",
  56. @"Samantha",
  57. @"Alexis",
  58. @"Lily",
  59. @"Grace",
  60. @"Hailey",
  61. @"Alyssa",
  62. @"Lillian",
  63. @"Hannah",
  64. @"Avery",
  65. @"Leah",
  66. @"Nevaeh",
  67. @"Sofia",
  68. @"Ashley",
  69. @"Anna",
  70. @"Brianna",
  71. @"Sarah",
  72. @"Zoe",
  73. @"Victoria",
  74. @"Gabriella",
  75. @"Brooklyn",
  76. @"Kaylee",
  77. @"Taylor",
  78. @"Layla",
  79. @"Allison",
  80. @"Evelyn",
  81. @"Riley",
  82. @"Amelia",
  83. @"Khloe",
  84. @"Makayla",
  85. @"Aubrey",
  86. @"Charlotte",
  87. @"Savannah",
  88. @"Zoey",
  89. @"Bella",
  90. @"Kayla", nil];
  91. NSArray *middleNameArray = [NSArray arrayWithObjects: @"Alexa",
  92. @"Peyton",
  93. @"Audrey",
  94. @"Claire",
  95. @"Arianna",
  96. @"Julia",
  97. @"Aaliyah",
  98. @"Kylie",
  99. @"Lauren",
  100. @"Sophie",
  101. @"Sydney",
  102. @"Camila",
  103. @"Jasmine",
  104. @"Morgan",
  105. @"Alexandra",
  106. @"Jocelyn",
  107. @"Gianna",
  108. @"Maya",
  109. @"Kimberly",
  110. @"Mackenzie",
  111. @"Katherine",
  112. @"Destiny",
  113. @"Brooke",
  114. @"Trinity",
  115. @"Faith",
  116. @"Lucy",
  117. @"Madelyn",
  118. @"Madeline",
  119. @"Bailey",
  120. @"Payton",
  121. @"Andrea",
  122. @"Autumn",
  123. @"Melanie",
  124. @"Ariana",
  125. @"Serenity",
  126. @"Stella",
  127. @"Maria",
  128. @"Molly",
  129. @"Caroline",
  130. @"Genesis",
  131. @"Kaitlyn",
  132. @"Eva",
  133. @"Jessica",
  134. @"Angelina",
  135. @"Valeria",
  136. @"Gabrielle",
  137. @"Naomi",
  138. @"Mariah",
  139. @"Natalia",
  140. @"Paige",
  141. @"Rachel", nil];
  142.  
  143. // concatenate strings at index of array
  144. NSString *fullName = [NSString stringWithFormat:@"%@ %@", [firstNameArray objectAtIndex:a], [middleNameArray objectAtIndex:b]];
  145.  
  146. // display the newly created first & middle names
  147.  
  148. babyname.text = fullName;
  149.  
  150. }
  151. - (IBAction)saveName:(id)sender {
  152. // save current baby name to array
  153. NSMutableArray *babyNameArray = [[NSMutableArray alloc] init];
  154.  
  155. [babyNameArray addObject:babyname.text];
  156.  
  157. // save list of babynames to nsuserdefaults
  158.  
  159. [[NSUserDefaults standardUserDefaults] setObject:babyNameArray forKey:@"My Key"];
  160.  
  161.  
  162. // for testing log names listed in nsuserdefaults
  163. NSLog(@"%@", [[NSUserDefaults standardUserDefaults] dictionaryRepresentation]);
  164.  
  165.  
  166.  
  167. }
  168.  
  169. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement