Skip to content

Instantly share code, notes, and snippets.

View jkaufman's full-sized avatar

Justin Kaufman jkaufman

View GitHub Profile

The following line omitted the text in bold:

button.enabled = [string length] > 0;

As a result, the string's length, a value of type NSUInteger, or unsigned long on 64-bit, was stuffed into a BOOL, which is actually a typedef for signed char. Comparisons of this frankenbool against NO yield the right result, but only for values below 255. Anything above might truncate and yield an erroneous NO. Comparing against YES, meanwhile, only returns the right result for the value 1. By setting the button's enabled state to an unsigned integer, the code was effectively disabling the button for all strings shorter or longer than one character.

@jkaufman
jkaufman / gist:8fa653fd6ab9221830e2
Created August 29, 2014 16:47
UITextField rightView mode
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
view.backgroundColor = [UIColor redColor];
self.textField.rightView = view;
self.textField.rightViewMode = UITextFieldViewModeUnlessEditing;
}

😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 😱 :scream

@jkaufman
jkaufman / 0_reuse_code.js
Created November 8, 2016 16:27
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console