Take the 2-minute tour ×  Given (arbitrarily):  CGRect frame =
CGRectMake(0.0f, 0.0f, 100.0f, 30.0f);  What's the difference
between the following two code snippets?       UIButton *button
= [UIButton buttonWithType:UIButtonTypeCustom];     button.frame
= frame;       UIButton *button = [[[UIButton alloc]
initWithFrame:frame] autorelease]; share|improve this question
add comment  5 Answers  I think they're equivalent. Haha! Trick
question you sneaky little punk!     1. -buttonWithType: returns
an autoreleased UIButton object.    2. +[NSObject alloc]
defaults scalar instance variables to 0, so buttonType should be
0, or UIButtonTypeCustom.  Pros & Cons    1. You could argue
that it's clearer to use -buttonWithType: and set buttonType
explicitly and that it's safer in case Apple changes
UIButtonTypeCustom to be 1 instead of 0 (which will most
certainly never happen).    2. On the other hand, you could also
argue that it's clear & safe enough to use -initWithFrame. Plus,
many of the Xcode sample projects, such a