Search code examples
objective-cconvenience-methods

Convenience class method vs alloc init


I understand that objects may perform more effectively if you manually allocate and initialize them (ARC should have taken care of the majority of this, right?), however, is it really THAT BIG of a difference in performance if you were to just use convenience class methods every time to create objects?

Examples:

NSString *message = [[NSSTring alloc] initWithFormat:@"text %@", message];

vs

NSString *message = [NSString stringWithFormat:@"text %@", message];

Solution

  • There is no meaningful difference in performance.

    Even being concerned about that is a premature optimization and as Donald Knuth states: "Premature optimization is the root of all evil (or at least most of it) in programming."

    Code clarity is a much more important issue.