Skip to content

Instantly share code, notes, and snippets.

@joanromano
joanromano / gist:6159162
Created August 5, 2013 20:12
Vertically center view groups in superview
- (void)centerViewGroupInY:(NSArray *)views withFixedSpace:(CGFloat)space options:(NSLayoutFormatOptions)options
{
if (![views count])
return;
NSMutableString *mutableConstraint = [@"V:|[topSpacer(==bottomSpacer)]" mutableCopy];
UIView *topSpacer, *bottomSpacer;
NSDictionary *metrics = @{@"space":@(space)};
NSMutableDictionary *viewsMutableDictionary = [NSMutableDictionary dictionary];
@joanromano
joanromano / gist:5500953
Created May 2, 2013 08:36
Generic typeof for weak self references
__weak typeof(self) weakSelf = self;
@joanromano
joanromano / gist:5116211
Created March 8, 2013 12:38
Returns the NSRange of a given regular expression pattern
- (NSRange)rangeOfRegularExpressionPattern:(NSString *)pattern inString:(NSString *)string
{
NSRegularExpression *expression = [NSRegularExpression regularExpressionWithPattern:pattern options:nil error:nil];
NSTextCheckingResult *result = [expression firstMatchInString:string options:nil range:NSMakeRange(0, [string length])];
return result.range;
}
@joanromano
joanromano / gist:4740046
Last active December 12, 2015 07:58
Generic typeof for weak self references
__weak typeof(self) weakSelf = self;