Skip to content

Instantly share code, notes, and snippets.

@pita5
Created June 5, 2013 22:47
Show Gist options
  • Save pita5/5717926 to your computer and use it in GitHub Desktop.
Save pita5/5717926 to your computer and use it in GitHub Desktop.
- (void)swap:(id*)a with:(id*)b
{
id c = *a;
*a = *b;
*b = c;
}
id a = @1;
id b = @2;
NSLog(@"a is %@",a);
NSLog(@"b is %@",b);
[self swap:&a with:&b];
NSLog(@"a is %@",a);
NSLog(@"b is %@",b);
2013-06-05 23:45:46.548 App[26572:c07] a is 1
2013-06-05 23:45:46.549 App[26572:c07] b is 2
2013-06-05 23:45:46.549 App[26572:c07] a is 2
2013-06-05 23:45:46.549 App[26572:c07] b is 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment