Skip to content

Instantly share code, notes, and snippets.

@jkaufman
Last active August 29, 2015 14:05
Show Gist options
  • Save jkaufman/442f7f14ab698b30b94e to your computer and use it in GitHub Desktop.
Save jkaufman/442f7f14ab698b30b94e to your computer and use it in GitHub Desktop.
BOOL error

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment