• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: how to check if a property is empty?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to check if a property is empty?


  • Subject: Re: how to check if a property is empty?
  • From: Jens Alfke <email@hidden>
  • Date: Sat, 29 Mar 2008 10:22:34 -0700


On 29 Mar '08, at 10:11 AM, Davide Benini wrote:

I half suspected something like this...

Well, for a _pointer_ type*, there is an "empty" value: NULL. (For object pointers the constant 'nil' is used, but they both have the same underlying value.)


When an Objective-C object is created, its storage is filled with zeroes. So instance variables that you haven't assigned a value to yet are guaranteed to be NULL, or nil, or zero. (In other words, Objective- C's 'alloc' calls 'calloc', not 'malloc'.)

But watch out — this doesn't apply to local variables in functions or methods. Those have random/garbage values until initialized. Same goes for raw memory allocated via 'malloc' — use 'calloc' if you want it zeroed.

—Jens

* It sounds like you're coming from a PHP background ... if you haven't done much C programming before, the distinction between pointers and scalars is likely to be confusing, since it doesn't exist in higher-level languages. If so, definitely find a good C textbook and read through that first!

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >how to check if a property is empty? (From: Davide Benini <email@hidden>)
 >Re: how to check if a property is empty? (From: Quincey Morris <email@hidden>)
 >Re: how to check if a property is empty? (From: Davide Benini <email@hidden>)

  • Prev by Date: Re: how to check if a property is empty?
  • Next by Date: Core Data migration
  • Previous by thread: Re: how to check if a property is empty?
  • Next by thread: Re: how to check if a property is empty?
  • Index(es):
    • Date
    • Thread