Skip to content

Instantly share code, notes, and snippets.

View dreampowder's full-sized avatar

Serdar Coşkun dreampowder

View GitHub Profile
@dreampowder
dreampowder / UICollectionView Delegates&Datasources
Created January 3, 2014 14:00
Copy-Paste Ready UICollectionView Datasources and Delegates for quick view creation
#pragma mark - UICollectionView Datasource
// 1
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
return 1;
}
// 2
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
return 1;
}
[aeiou] - matches exactly one lowercase vowel
[^aeiou] - matches a character that ISN'T a lowercase vowel (negated character class)
^[aeiou] - matches a lowercase vowel anchored at the beginning of the line
[^^] - matches a character that isn't a caret/'^'
^[^^] - matches a character that isn't a caret at the beginning of line
^[^.]. - matches anything but a literal period, followed by "any" character, at the beginning of line
[a-z] - matches exactly one character within the range of 'a' to 'z' (i.e. all lowercase letters)
[az-] - matches either an 'a', a 'z', or a '-' (literal dash)
[.*]* - matches a contiguous sequence (possibly empty) of dots and asterisks
[aeiou]{3} - matches 3 consecutive lowercase vowels (all not necessarily the same vowel)
@dreampowder
dreampowder / gist:65d45a7c58afb3511e89
Created September 3, 2014 13:31
Check if user has pressed back button on navigationcontroller
- (void)didMoveToParentViewController:(UIViewController *)parent
{
// parent is nil if this view controller was removed
}
@dreampowder
dreampowder / gist:437be35cf91efbe58989
Created October 20, 2014 11:27
Code for Moving view under the is navigation bar.
self.edgesForExtendedLayout = UIRectEdgeNone;
@dreampowder
dreampowder / gist:9ae1a45c57540a7a72bd
Created October 28, 2014 16:01
Get Days Between two dates
+ (NSInteger)getDaysBetween:(NSDate*)dateBegin
withDate:(NSDate*)dateEnd{
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [gregorianCalendar components:NSDayCalendarUnit
fromDate:dateBegin
toDate:dateEnd
options:0];
return [components day];
}
@dreampowder
dreampowder / gist:7d8b876f8ef8f06e10da
Created September 14, 2015 08:14
NSLocalizedString with format macro
#define NSLocalizedFormatString(fmt, ...) [NSString stringWithFormat:NSLocalizedString(fmt, nil), __VA_ARGS__]
@dreampowder
dreampowder / gist:bb8cd80a023fbfb7ed7d
Created September 28, 2015 13:04
CA Spring Animation Example
- (void)animateRefreshButton:(BOOL)willAnimate{
if (willAnimate) {
[self.btnRefresh setEnabled:NO];
CASpringAnimation* springRotation = [CASpringAnimation animationWithKeyPath:@"transform.rotation.z"];
springRotation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/];
springRotation.duration = 2.0f;
springRotation.cumulative = YES;
springRotation.repeatCount = INT_MAX;
springRotation.damping = 8;
@dreampowder
dreampowder / gist:0f351e0d25e08264e94e
Created October 1, 2015 12:34
Scrollview keyboard dismiss
tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
Or to dismiss when touch
tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive;
@dreampowder
dreampowder / NSArrayMagic.m
Created October 12, 2015 09:36 — forked from jarsen/NSArrayMagic.m
How to do lots of cool things with NSArray. Inspired by NSHipster and WWDC 2013 Session 228 - "Hidden Gems in Cocoa and Cocoa Touch"
NSArray *albums = @[[Album albumWithName:@"Random Access Memories" price:9.99f],
[Album albumWithName:@"Clarity" price:6.99f],
[Album albumWithName:@"Weekend in America" price:7.99f],
[Album albumWithName:@"Weekend in America" price:7.90f],
[Album albumWithName:@"Bangarang EP" price:2.99f]];
// Reversing an Array
__unused NSArray *reversed = albums.reverseObjectEnumerator.allObjects;
// PREDICATES
@dreampowder
dreampowder / java version switch
Created January 19, 2016 14:32
OSX Java version switch
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/