Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Objective-C Sins

Objective-C Sins

I have a confession to make. I've written some terrible Objective-C code. I guess you can say I've sinned. In this talk, I discuss common anti-patterns and how to avoid them.

This talk was originally presented to students of the iOS class at The Flatiron School. Without the actual talking to go with it, these slides are probably missing a lot of context. If you're confused about something, send me a message on twitter (@mb).

Matthew Bischoff

October 29, 2013
Tweet

More Decks by Matthew Bischoff

Other Decks in Technology

Transcript

  1. sin 1 |sin| noun an immoral act considered to be

    a transgression against divine law: a sin in the eyes of God | the human capacity for sin. ! • an act regarded as a serious or regrettable fault, offense, or omission: he committed the unforgivable sin of refusing to give interviews | humorous : with air like this, it's a sin not to go out.
  2. sin 1 |sin| noun an immoral act considered to be

    a transgression against divine law: a sin in the eyes of God | the human capacity for sin. ! • an act regarded as a serious or regrettable fault, offense, or omission: he committed the unforgivable sin of refusing to give interviews | humorous : with air like this, it's a sin not to go out.
  3. @mb

  4. Object retainCount? Actual retainCount [NSNumber numberWithInt:1] 1 2 @"Matt" 1

    1152921504606846975 [NSString stringWithString:@"Matt"] 1 1152921504606846975
  5. Key-Value Observing has the worst API in all of Cocoa.

    It’s awkward, verbose, and confusing. Mattt Thompson
  6. What’s the obvious thing to do, the easiest way to

    agree? Just do what the headers say. If it’s a property, treat it as such. If it’s not, don’t. ! And when in doubt, look it up. Brent Simmons
  7. Every piece of knowledge must have a single, unambiguous, authoritative

    representation within a system. Andy Hunt and Dave Thomas
  8. id

  9. #pragma mark - NSObject ! - (void)dealloc {} ! #pragma

    mark - UIViewController ! - (void)viewDidLoad {} ! #pragma mark - LCKDocumentsTableViewController ! - (void)setupRefreshControl {}
  10. Two-letter prefixes…are reserved by Apple for use in framework classes.

    ! Your own classes should use three letter prefixes.
  11. - (instancetype)initWithPerson:(LCKPerson *)person { self = [super initWithStyle:UITableViewStylePlain]; if (self)

    { _person = person; _dataStore = [NSMutableDictionary dictionary]; } return self; }
  12. - (id)initWithStyle:(UITableViewStyle)style { return [self initWithPerson:nil]; } ! - (instancetype)initWithPerson:(LCKPerson

    *)person { self = [super initWithStyle:UITableViewStylePlain]; if (self) { _person = person; _dataStore = [NSMutableDictionary dictionary]; } return self; }
  13. Property Description Example accessibilityLabel Identifies the accessibility element, but does

    not include the type of the control or view “Share” accessibilityValue The value is a localized string that contains the current value of an element “35 %” accessibilityHint Description of the result of performing an action on the element. “Selects the message”
  14. Symbol Value Meaning NULL (void *)0 literal null value for

    C pointers nil (id)0 literal null value for Objective-C objects Nil (Class)0 literal null value for Objective-C classes NSNull [NSNull null] singleton object used to represent null