Skip to content

Instantly share code, notes, and snippets.

@inailuy
inailuy / nothing
Created March 13, 2013 21:24
NSNULL nil NULL Nil
NULL (void *)0 literal null value for C pointers
nil (id)0 literal null value for Objective-C objects
Nil (Class)0 literal null value for Objective-C classes
NSNull [NSNull null] singleton object used to represent null
@inailuy
inailuy / Removing compiler warning
Last active December 14, 2015 22:09
Using #pragma to avoid compiler errors
#pragma clang diagnostic push
// Code that produces warnings
#pragma clang diagnostic pop
- (void)method
{
CGPoint velocity = [sender translationInView:view];
if (sender.state == UIGestureRecognizerStateEnded)
{
if (velocity.x > 0)
{
[self switchedCarsWithDirection:LEFT];
}
[navigationBar setBackgroundImage:[UIImage imageNamed:@"image"] forBarMetrics:UIBarMetricsDefault];
#define WINDOW_WIDTH [[UIScreen mainScreen] bounds].size.width
#define WINDOW_HEIGHT [[UIScreen mainScreen] bounds].size.height
@inailuy
inailuy / Adding NavigationBar Button
Last active December 14, 2015 02:48
Adding Navigation button to the right side
UIImage *buttonImage = [UIImage imageNamed:@"image"];
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 50, 44);
[button setImage:buttonImage forState:UIControlStateNormal];
[button addTarget:self
action:@selector(nil)
forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
self.navigationItem.rightBarButtonItem = barButtonItem;
@inailuy
inailuy / int to NSString with format
Created February 22, 2013 16:56
For currencies or large numers that have commas after every 3 digits eg: 1,000,000 Converting int to string with commas money formatter
NSString *numberWithCommas = [NSNumberFormatter localizedStringFromNumber:@(intNumber)
numberStyle:NSNumberFormatterDecimalStyle];
@inailuy
inailuy / Global App Delegate
Created February 21, 2013 19:57
Creating a global instance of app delegate for a iOS project
+ (AppDelegate *)instance
{
return (AppDelegate *)[UIApplication sharedApplication].delegate;
}
@inailuy
inailuy / Shadows
Last active December 13, 2015 23:09
making a shadow for a view in iOS
//Adds a shadow to sampleView
CALayer *layer = self.sampleView.layer;
layer.shadowOffset = CGSizeMake(1, 1);
layer.shadowColor = [[UIColor blackColor] CGColor];
layer.shadowRadius = 4.0f;
layer.shadowOpacity = 0.80f;
layer.shadowPath = [[UIBezierPath bezierPathWithRect:layer.bounds] CGPath];
@inailuy
inailuy / Open Maps iOS
Created February 15, 2013 22:51
Open maps application in iOS with a location within a app.
NSString *mapsURL = @"http://maps.google.com/maps?q=";
if ([[[[UIDevice currentDevice] systemVersion] substringToIndex:1] intValue] >= 6) // if iOS 6 or greater use apple maps
{
mapsURL = @"http://maps.apple.com/maps?q=";
}
NSString *mapaddress = [mapsURL stringByAppendingString:address];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[mapaddress stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]]];