Skip to content

Instantly share code, notes, and snippets.

@paolonl
paolonl / gitignore
Last active August 29, 2015 14:19
iOS git ignore
# Xcode
#
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
@paolonl
paolonl / NSString+EmailValidation
Created August 19, 2013 15:06
Regular Expression for validating email address
-(BOOL) NSStringIsValidEmail:(NSString *)checkString
{
BOOL stricterFilter = YES; // Discussion http://blog.logichigh.com/2010/09/02/validating-an-e-mail-address/
NSString *stricterFilterString = @"[A-Z0-9a-z\\._%+-]+@([A-Za-z0-9-]+\\.)+[A-Za-z]{2,4}";
NSString *laxString = @".+@([A-Za-z0-9]+\\.)+[A-Za-z]{2}[A-Za-z]*";
NSString *emailRegex = stricterFilter ? stricterFilterString : laxString;
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
return [emailTest evaluateWithObject:checkString];
}
@paolonl
paolonl / UIImage+Rotation
Last active July 3, 2018 14:16
Rotate UIImage/CGImageRef
- (UIImage *)rotateImage:(UIImage *)image ofAngle:(CGFloat)degrees {
CGImageRef imgRef = image.CGImage;
CGFloat angleInRadians = degrees * (M_PI / 180);
CGFloat width = CGImageGetWidth(imgRef);
CGFloat height = CGImageGetHeight(imgRef);
CGRect imgRect = CGRectMake(0, 0, width, height);
CGAffineTransform transform = CGAffineTransformMakeRotation(angleInRadians);
CGRect rotatedRect = CGRectApplyAffineTransform(imgRect, transform);
@paolonl
paolonl / gist:6201513
Last active December 20, 2015 21:59
Make a class sub-scriptable
/*
Define the proper methods based on the
desired kind of subscripting, indexed
or keyed
*/
@interface IndexedSubscriptable
- (id)objectAtIndexedSubscript:(NSUInteger)idx
- (void)setObject:(id)anObject atIndexedSubscript:(NSUInteger)index
@end
@paolonl
paolonl / gist:6201381
Last active December 20, 2015 21:58 — forked from ksm/gist:3689574
How to get a constant literal container to work.
/*
Source: WWDC2012 Modern Objective-C talk
How to get a constant literal container to work.
*/
@implementation MyClass
static NSArray *thePlanets;
+ (void)initialize {
/*
Enum with Fixed Underlying Type
New with Xcode 4.4
Via WWDC2012 Session 405 - Modern Objective-C
Results in better code completion and stronger type checking.
Use -Wconversion compiler flag to check for enum type errors.
-Wswitch for checking if switch statement is fully handled for enum.
*/