• 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
Newbie Q about NSCoder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Newbie Q about NSCoder


  • Subject: Newbie Q about NSCoder
  • From: email@hidden
  • Date: Wed, 21 Sep 2005 11:11:32 +0200 (CEST)
  • Importance: Normal

  Hello all,

 I'm rather confused about how the NSCoder works. Specifically, I have
trouble understanding the decodeObject method. Consider
the following example (from Aaron Hillegass' book)

  -(id) initWithCoder : (NSCoder*) coder {
          ....
       [self setPersonName : [coder decodeObject]];
       [coder decodeValueOfObjCType:@encode(float) at:&expectedRaise];]
          ....
   }

where the class considered (called Person) has two instance
varibales personName and expectedRaise, and two methods

   -setPersonName : (NSString*) s;
   -setExpectedRaise : (float) f;

   My questions are :

- what is exactly the type of the value [coder decodeObject] in the code
above ? If we look at the signature of the setPersonName method, it seems
that its type is NSString*. But it's just a deceiving feature of
Objective-C syntax,
right ? The type of   [coder decodeObject] is simply id ; [coder
decodeObject]
is a big machine which given a class and an instance produces the
corresponding
value.

- If so, why is it not used uniformly in each case ; i.e, could the two lines
above be replaced with

 [self setPersonName : [coder decodeObject]];
 [self setExpectedRaise : [coder decodeObject]];

     Thanks in advance for any help.

                                                                             Ewan




 _______________________________________________
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: Newbie Q about NSCoder
      • From: Charlton Wilbur <email@hidden>
  • Prev by Date: Re: [NSUndoManager undoMenuItemTitle]
  • Next by Date: Re: [NSUndoManager undoMenuItemTitle]
  • Previous by thread: NSPanel, DO & applications vs. bundles
  • Next by thread: Re: Newbie Q about NSCoder
  • Index(es):
    • Date
    • Thread