Check Current Orientation


if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft){
        //do something or rather
        NSLog(@"landscape left");
    }
    if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight){
        //do something or rather
        NSLog(@"landscape right");
    }
    if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait){
        //do something or rather
        NSLog(@"potrait");
    }
    if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown){
        //do something or rather
        NSLog(@"potrait upside down");
    }

Or you can also use this:

[[UIDevice currentDevice] orientation]

Swipe Gesture Recognizer


UISwipeGestureRecognizer * swipeRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRightAction:)];
swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
swipeRight.delegate = self;
[self.view addGestureRecognizer:swipeRight];
[swipeRight release];
swipeRight = nil;

Make Animation Slow at the Beginning

[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
mainImage.alpha = 0.0f;
[UIView commitAnimations];

Details:
UIViewAnimationCurveEaseInOut: The default Value, slow at beginning and end of animation
UIViewAnimationCurveEaseIn: Slow at beginning, the speeds up
UIViewAnimationCurveEaseOut: Animation slows at end of animation
UIViewAnimationCurveLinear: Uniform speed throughout duration

Sort Array with comparator

For a mutable array of dictionaries:

NSMutableArray *aMutableArray = [NSMutableArray arrayWithObjects:
         [NSDictionary dictionaryWithObjectsAndKeys:
          @"A", @"name",
          [NSNumber numberWithInt:6], @"value", nil],
         [NSDictionary dictionaryWithObjectsAndKeys:
          @"C", @"name",
          [NSNumber numberWithInt:2], @"value", nil],
         [NSDictionary dictionaryWithObjectsAndKeys:
          @"B", @"name",
          [NSNumber numberWithInt:4], @"value", nil], nil];
In this case case here's how you sort it by value:


NSSortDescriptor *aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"value" ascending:YES];
[aMutableArray sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]];



Otherwise:


NSSortDescriptor *lastNameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastname" ascending:YES comparator:^(id left, id right) {
float v1 = [left floatValue];
float v2 = [right floatValue];
if (v1 < v2)
return NSOrderedAscending;
else if (v1 > v2)
return NSOrderedDescending;
else
return NSOrderedSame;
}];

[data sortUsingDescriptors:[NSArray arrayWithObject:lastNameDescriptor]];

sort an array of strings alphabetically when the strings contains åäö

NSArray *strings=[NSArray arrayWithObjects:@"as", @"ol", @"st", @"br", @"ög", @"år", @"ös", nil];
NSLocale *locale=[[NSLocale alloc] initWithLocaleIdentifier:@"sv_SE"];

NSArray *sorted=[strings sortedArrayUsingComparator:^(NSString *first, NSString *second) {
return [first compare:second
options:0
range:NSMakeRange(0, [first length])
locale:locale];
}];

for (NSString *s in sorted) { NSLog(@"%@", s); }

output:
as br ol st år ög ös

Streaming Radio

#import <MediaPlayer/MPMoviePlayerController.h>

MPMoviePlayerController* player;
NSURL *theURL = [NSURL URLWithString:@"http://someurl.com"];
player = [[MPMoviePlayerController alloc] initWithContentURL:theURL];
[player prepareToPlay];
...
[player play];

Disable the UITableView Selection Highlighting

cell.selectionStyle = UITableViewCellSelectionStyleNone;

Sort Array by Number

NSArray *order = [order sortedArrayUsingComparator: ^(id first, id second) {
return [(NSString *)first compare:(NSString *)second options: NSNumericSearch];
}];

Sort Array

NSArray *myArray = [myArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];

or

NSSortDescriptor *lastNameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES];
[myArray sortUsingDescriptors:[NSArray arrayWithObject:lastNameDescriptor]];

Change Default Scrolling Behavior of UITableView Section Header

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

CGFloat sectionHeaderHeight = 40;

if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {

scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);

} else if (scrollView.contentOffset.y>=sectionHeaderHeight) {

scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);

}

}