0

Could someone explain why I get this?

CGRect rect;
NSLog(@"rect is %@", NSStringFromCGRect(rect));
// rect is {{-1.99891, 2.58159e-38}, {1.91754e-41, 8.46552e-39}}

And what about primitives?

Philip007
  • 3,190
  • 7
  • 46
  • 71

1 Answers1

5

Objective-C initializes instance variables to 0. It does not necessarily initialize local variables to 0.

If you have ARC enabled, Objective-C initializes local variables that are object pointers (e.g. NSObject *, UIView *, etc.) to nil. But it doesn't initialize any other local variables. Other local variables (and object pointers if ARC is disabled) will have random values unless you explicitly initialize them.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848