Newbie Q about NSCoder
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