Skip to content

Instantly share code, notes, and snippets.

View frankus's full-sized avatar

Frank Schmitt frankus

  • Bellingham, WA, USA
View GitHub Profile
@frankus
frankus / AffectedRows.m
Last active August 29, 2015 14:05
Switch between sorted arrays with intelligent animations
/**
Returns the index paths of the rows affected by switching between two
sorted (but not necessarily unique) arrays.
@param old The array to be switched from.
@param new The array to be switched to.
@param keyPath the key path to compare ("@self" to use raw value)
@return An array of three arrays, the first containing index paths
for modified rows, the second for deleted rows, and the third for
@frankus
frankus / gist:e9660a376451f21e73f3
Created August 20, 2014 20:31
Pretty good (North America only) phone number UITextField
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField == self.myPhoneTextField) {
NSString *newText = [textField.text stringByReplacingCharactersInRange:range withString:string];
BOOL deleting = [newText length] < [textField.text length];
NSString *stripppedNumber = [newText stringByReplacingOccurrencesOfString:@"[^0-9]" withString:@"" options:NSRegularExpressionSearch range:NSMakeRange(0, [newText length])];
NSUInteger digits = [stripppedNumber length];
if (digits > 10)
stripppedNumber = [stripppedNumber substringToIndex:10];