• 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
Two odd newbie questions ;-)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Two odd newbie questions ;-)


  • Subject: Two odd newbie questions ;-)
  • From: Felix Schwarz <email@hidden>
  • Date: Thu, 12 May 2005 20:33:18 +0200

Hi everyone,

I'm (pretty) new to Objective-C programming. One thing I keep wondering about, is whether I can safely write e.g.

    myFloat = [[valueLimits objectForKey:myKey] floatValue];

or should rather write:

    if (myNsFloat = [valueLimits objectForKey:myKey])
    {
        myFloat = [myNsFloat floatValue];
    }

The same goes with

    [new retain];
    [old release];
    old = new;

instead of

    if (new)
    {
        [new retain];
    }

    if (old)
    {
        [old release];
    }

    old = new;

Is it legal to perform methods on (or send messages to) "null" or "nil" objects?
Is there a guaranteed result (thinking of above myFloat example - will it be null in case the dictionary does not contain the key or have an undefined value?)?


I ask those questions because - most of the time - I don't see *any* error checking in place in sample code, so I wonder whether the sample code simply is written in a bad style or it uses a "feature" of the language or Cocoa.

Thanks in advance!

Best regards,
Felix Schwarz
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Two odd newbie questions ;-)
      • From: Ondra Cada <email@hidden>
    • Re: Two odd newbie questions ;-)
      • From: Pontus Ilbring <email@hidden>
  • Prev by Date: Re: Why would a defined selector not be found at runtime?
  • Next by Date: Using Core-Image in GUI
  • Previous by thread: NSScanner With Multiple Characters
  • Next by thread: Re: Two odd newbie questions ;-)
  • Index(es):
    • Date
    • Thread