Alex Rivera | Logout

Can I rely on nil UIView returning CGRectZero for its frame?

Asked 2012-04-07T04:35:22.343
9

Yes, I saw this:

If the method returns a struct, as defined by the Mac OS X ABI Function Call Guide to be returned in registers, then a message sent to nil returns 0.0 for every field in the struct. Other struct data types will not be filled with zeros.

I just don't get it.

Edit
Report

1 Answer

15

If you're using recent versions of the LLVM Compiler (Xcode 4.2 or later), then yes, messaging nil with a struct-returning method will produce a zero-filled struct. In the case of CGRect, that means a rect equal to CGRectZero.

Source: Greg Parker, who works at Apple on the ObjC runtime.

answered 2012-04-07T04:55:51.643

Your Answer