vendredi 14 août 2015

Assigning NSUInteger to BOOL conceptual understanding

I am trying to look for a good answer to the concept of BOOL. As I understand, a zero is a false value, and non-zero is a true value. Thinking this I assigned string length into a BOOL variable. Now, this works fine for iOS > 6. On iOS 6 I see strange results. For string with odd length, isEnabled is turing True but for strings with even length, isEnabled is turing False.

BOOL isEnabled = myString.length;

Please help me understand this. Of course, now I've been assigning expressions to BOOL variable like this:

BOOL isEnabled = myString.length > 0;

Exact code:

- (void)textViewDidChange:(UITextView *)iTextView {
    self.navigationItem.rightBarButtonItem.enabled = [[self.noteTextView.text trim] length];
}

PS: As mentioned, myString is changing in length; from 'a' to 'ab' to 'abc' etc.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire