Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 718495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:32:00+00:00 2026-05-14T05:32:00+00:00

So I am seemingly encountering some strange behavior when using NSString ‘s -sizeWithFont family

  • 0

So I am seemingly encountering some strange behavior when using NSString‘s -sizeWithFont family of method calls depending on whether or not I’m invoking it on the iPhone Simulator or an actual device.

Simply enough, when the receiver of the -sizeWithFont:constrainedToSize:lineBreakMode: method call is nil, the resulting CGSize passed back on the Simulator is {0, 0}. However, on the device, the return result is the same CGSize value that I specify in the method call as the constrainedToSize: parameter. See the following log statements:

Simulator:

someString: (null)
someStringSize: {0, 0}

Device:

someString: (null)
someStringSize: {185, 3.40282e+38}

The behavior on the Simulator is what I would expect. Not that this issue is difficult to circumvent, but 1) I’m a little confused why this family of functions would behave differently on the Simulator and an actual device, and 2) why does calling a method on a nil receiver return a particular, deterministic result?

Thanks for any pointers or insight you guys can provide!

EDIT: I suppose I should mention that I’m building against the 3.1 SDK.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T05:32:00+00:00Added an answer on May 14, 2026 at 5:32 am

    Apple’s documentation on Sending messages to nil kind of explains this:

    The value returned from a message to nil may also be valid:

    • If the method returns an object, then a message sent to nil returns 0 (nil) …
    • If the method returns any pointer type, any integer scalar of size less than or equal to sizeof(void*), a float, a double, a long double, or a long long, then a message sent to nil returns 0.
    • 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 data structure. Other struct data types will not be filled with zeros.
    • If the method returns anything other than the aforementioned value types the return value of a message sent to nil is undefined.

    Although this document does not talk specifically about the iPhone (and it was written before the iPhone SDK was released), note the third and fourth bullet points: if the method returns a struct (such as CGSize), the behavior is platform-dependent. Only values that are returned in CPU registers are filled with zeros. I am not an expert on the ARM architecture of the iPhone, but it is likely that on the iPhone, the return value of sizeWithFont: is not returned in registers, as opposed to i386. In that case, the returned struct would be filled with zeros when running on the simulator while the value would be undefined when running on the iPhone.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.