Skip to content

Instantly share code, notes, and snippets.

@benjaminsnorris
benjaminsnorris / ViewController.m
Created November 24, 2014 16:31
Resized Picker View
//
// ViewController.m
// test
//
// Created by Joshua Howland on 11/21/14.
// Copyright (c) 2014 Wired In LLC. All rights reserved.
//
#import “ViewController.h”
@benjaminsnorris
benjaminsnorris / TableViewController.m
Created November 25, 2014 23:51
Dynamic Cell Heights
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 60.0;
@benjaminsnorris
benjaminsnorris / Parser.m
Created December 1, 2014 16:58
Parse string as equation
if ([[equation substringToIndex:1] isEqualToString:@"+"]) {
equation = [equation substringFromIndex:1];
}
NSExpression *equationExpression = [NSExpression expressionWithFormat:equation];
NSNumber *equationNumber = [equationExpression expressionValueWithObject:nil context:nil];
@benjaminsnorris
benjaminsnorris / ArrayComparison.m
Created December 3, 2014 22:54
Compare arrays based on key
if (![[array1 valueForKey:@"uniqueId"] isEqualToArray:[array2 valueForKey:@"uniqueId"]]) {
// The arrays contain the same objects that each have an attribute of "uniqueId"
}
@benjaminsnorris
benjaminsnorris / KeyboardHandler.m
Last active August 29, 2015 14:10
Responding to keyboard
#pragma mark - Keyboard Management
- (void)registerForKeyboardNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow: (NSNotification*) aNotification {
NSDictionary* info = [aNotification userInfo];
@benjaminsnorris
benjaminsnorris / NavAndStatusBarHeight.m
Created December 23, 2014 05:29
Return height of nav bar plus status bar
- (CGFloat)navAndStatusBarHeight {
return self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].statusBarFrame.size.height;
}
@benjaminsnorris
benjaminsnorris / ViewController.m
Created December 30, 2014 18:32
NavController Toolbar
- (void)setUpBottomToolbar {
self.navigationController.toolbar.tintColor = [UIColor orangeColor];
self.navigationController.toolbarHidden = NO;
self.viewPlayOrHistory = [[UISegmentedControl alloc] initWithItems:@[@"Standard", @"History"]];
self.viewPlayOrHistory.selectedSegmentIndex = 0;
UIBarButtonItem *viewSwitchButtonItem = [[UIBarButtonItem alloc] initWithCustomView:self.viewPlayOrHistory];
[self.viewPlayOrHistory addTarget:self action:@selector(switchViewToPlayOrHistory) forControlEvents:UIControlEventValueChanged];
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];
@benjaminsnorris
benjaminsnorris / GetPersonInfo.m
Created January 10, 2015 16:23
Get multiple values from selected contacted
+ (NSDictionary *)getMultipleValuesForPerson:(ABRecordRef)person forProperty:(ABPropertyID)property sanitizeToNumbers:(BOOL)sanitize {
NSMutableDictionary *mutableValuesWithLabels = [NSMutableDictionary dictionary];
ABMultiValueRef values = ABRecordCopyValue(person, property);
if (values && ABMultiValueGetCount(values) > 0)
{
for (CFIndex index = 0; index < ABMultiValueGetCount(values); index++) {
NSString *label = CFBridgingRelease(ABMultiValueCopyLabelAtIndex(values, index));
NSString *value = CFBridgingRelease(ABMultiValueCopyValueAtIndex(values, index));
if (sanitize) {
value = [[value componentsSeparatedByCharactersInSet:[[NSCharacterSet decimalDigitCharacterSet] invertedSet]] componentsJoinedByString:@""];
@benjaminsnorris
benjaminsnorris / DataSource.h
Last active August 29, 2015 14:14
TableView FetchedResultsController
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
@interface DXListTableViewDataSource : NSObject <UITableViewDataSource>
@property (nonatomic, strong) NSFetchedResultsController *fetchedResultsController;
- (void)registerTableView:(UITableView *)tableView;
- (void)configureFetchedResultsControllerForTableView:(UITableView *)tableView;
@benjaminsnorris
benjaminsnorris / CustomView.h
Last active August 29, 2015 14:15
Filling Segmented Custom View
//
// FillingSegmentedCircleView.h
// Created by Ben Norris on 2/20/15.
// Copyright (c) 2015 BSN Design. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface FillingSegmentedCircleView : UIView