Skip to content

Instantly share code, notes, and snippets.

@sanketfirodiya
sanketfirodiya / gist:8bf009c98b42bd3b0469
Created September 9, 2014 00:09
Hide text on back button, copy this in the presentingViewController
UIBarButtonItem *backButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
[self.navigationItem setBackBarButtonItem:backButtonItem];
@sanketfirodiya
sanketfirodiya / gist:136f016d2fc9ebed09dd
Created September 19, 2014 17:44
Find UITableViewCell based on subView
#import "UIView+UIViewCategory.h"
@implementation UIView (UIViewCategory)
- (UIView *)findSuperViewWithClass:(Class)superViewClass {
UIView *superView = self.superview;
UIView *foundSuperView = nil;
while (nil != superView && nil == foundSuperView) {
@sanketfirodiya
sanketfirodiya / gist:76db6c0d39c326fb1cd6
Last active August 29, 2015 14:07
Hide UITableView empty cells
self.uiTableView.tableFooterView = [[UIView alloc] init];
security find-identity -v -p codesigning
codesign -vv -d Example.app
@sanketfirodiya
sanketfirodiya / gist:67684baaab45b164d66c
Created November 11, 2014 20:46
NSURLSession Sample
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithURL:[NSURL URLWithString:@"https://itunes.apple.com/search?term=apple&media=software"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@", json);
}];
[dataTask resume];
@sanketfirodiya
sanketfirodiya / gist:15568b0ab7774415569b
Created March 6, 2015 02:10
Register custom UITableViewCell
- (void)viewDidLoad
{
[super viewDidLoad];
UINib *nib = [UINib nibWithNibName:@"ItemCell" bundle:nil];
[[self tableView] registerNib:nib forCellReuseIdentifier:@"ItemCell"];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Create an instance of ItemCell
#ifdef DEBUG
# define DLog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#else
# define DLog(...)
#endif
#define ALog(fmt, ...) NSLog((@"%s [Line %d] " fmt), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__);
#ifdef DEBUG
# define ULog(fmt, ...) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"%s\n [Line %d] ", __PRETTY_FUNCTION__, __LINE__] message:[NSString stringWithFormat:fmt, ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]; [alert show]; }
#else
# define ULog(...)
@sanketfirodiya
sanketfirodiya / gist:24233aaa75f413df708c
Created May 1, 2015 16:14
Interactive notifications for iOS8
UIMutableUserNotificationAction *notificationAction = [[UIMutableUserNotificationAction alloc] init];
notificationAction.identifier = @"Mute";
notificationAction.title = @"Mute";
notificationAction.activationMode = UIUserNotificationActivationModeBackground;
notificationAction.destructive = NO;
notificationAction.authenticationRequired = NO;
UIMutableUserNotificationCategory *notificationCategory = [[UIMutableUserNotificationCategory alloc] init];
notificationCategory.identifier = @"mute";
[notificationCategory setActions:@[notificationAction] forContext:UIUserNotificationActionContextDefault];
@sanketfirodiya
sanketfirodiya / gist:f9209bf0ffdd63f14003
Created May 10, 2015 17:12
NSData --> NSDictionary
NSDictionary *responseDictionary = [[NSDictionary alloc] init];
responseDictionary = [NSJSONSerialization JSONObjectWithData:responseData
options:NSJSONReadingMutableContainers
error:nil];
@sanketfirodiya
sanketfirodiya / gist:3b7b9dfbbeb8bc97a30b
Last active April 26, 2016 06:51
Check if BST is balanced
- (BOOL)isBSTBalanced:(Node *)root {
return ([self maxHeight:root] - [self minHeight:root] <= 1);
}
- (NSUInteger)maxHeight:(Node *)root {
if (root == null) {
return 0;
}
return MAX([self maxHeight:root.leftNode], [self maxHeight:root.rightNode]) + 1;