Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. @interface ViewController ()
  2. @end
  3.  
  4.  
  5. @implementation ViewController
  6. @synthesize textField,string1,string2,reverseArray,myArray;
  7. @synthesize Label1;
  8. - (IBAction)Reverse:(UIButton *)sender {
  9. reverseArray=[[NSMutableArray alloc]init];
  10. string1=[[NSString alloc]init];
  11. string2=[[NSString alloc]init];
  12. string1=textField.text;
  13. myArray=[[NSMutableArray alloc]init];
  14. for (int i=0; i<=string1.length-1; i++) {
  15. [myArray insertObject:[[NSString alloc] initWithFormat:@"%c",[string1 characterAtIndex:i]] atIndex:i];
  16.  
  17. }
  18. for (int j=0; j<=myArray.count-1; j++) {
  19. [reverseArray insertObject:[myArray objectAtIndex:myArray.count-1] atIndex:j];
  20. [myArray removeLastObject];
  21.  
  22.  
  23. }
  24. NSLog(@"%@",myArray);
  25. NSLog(@"%@",reverseArray);
  26.  
  27. First iteration: j=0; myArray.count - 1 = 4
  28. Second iteration: j=1; myArray.count - 1 = 3
  29. Third iteration: j=2; myArray.count - 1 = 2
  30.  
  31. for( int j = string1.length -1; j >= 0; j-- ) {
  32. [reverseArray addObject:[myArray objectAtIndex:j]];
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement