Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / TableViewController.m
Created November 25, 2014 23:51
Dynamic Cell Heights
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 60.0;
@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 / GradientView.h
Created November 24, 2014 16:28
Gradient View
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@interface GradientView : UIView
@property (nonatomic, strong) UIColor *startColor;
@property (nonatomic, strong) UIColor *midpointColor;
@property (nonatomic, strong) UIColor *finishColor;
@property (nonatomic, readwrite) float progress;
@benjaminsnorris
benjaminsnorris / ContactsViewController.m
Created November 22, 2014 02:14
Updating User from Contacts
- (void)updateUserWithContactInfo {
PFUser *currentUser = [PFUser currentUser];
NSString *name = currentUser[nameKey];
NSArray *people = (NSArray *)CFBridgingRelease(ABAddressBookCopyPeopleWithName(ABAddressBookCreateWithOptions(NULL, NULL), (__bridge CFStringRef)(name)));
if (people != nil && people.count > 0) {
ABRecordRef person = (__bridge ABRecordRef)[people objectAtIndex:0];
NSData *photoData = CFBridgingRelease(ABPersonCopyImageDataWithFormat(person, kABPersonImageFormatThumbnail));
NSString *firstName = CFBridgingRelease(ABRecordCopyValue(person, kABPersonFirstNameProperty));
NSString *lastName = CFBridgingRelease(ABRecordCopyValue(person, kABPersonLastNameProperty));
@benjaminsnorris
benjaminsnorris / main.js
Created November 21, 2014 01:17
Parse Cloud Code Attempt
Parse.Cloud.define("inviteRecipientLogic", function(request, response) {
Parse.Cloud.useMasterKey();
var InviteRecipient = Parse.Object.extend("InviteRecipient");
var Invite = Parse.Object.extend("Invite");
var inviteRecipientQuery = new Parse.Query(InviteRecipient);
var userId = request.params.id;
var user = new Parse.User();
user.id = userId;
@benjaminsnorris
benjaminsnorris / TableViewController.m
Created November 17, 2014 23:42
Edit Actions for Table View Row
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewRowAction *removeButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Remove" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
[self deletePlayerAtIndexPath:indexPath];
self.game.startingNumberOfPlayers = @(self.game.startingNumberOfPlayers.integerValue - 1);
}];
UITableViewRowAction *resetScoreButton = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Reset Score" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
[self.game resetScoresForPlayer:[self.fetchedResultsControllerDataSource.fetchedResultsController objectAtIndexPath:indexPath]];
}];
resetScoreButton.backgroundColor = [UIColor primaryColorLight];
return @[removeButton,resetScoreButton];