• 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: Unarchiving Problem Solved
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unarchiving Problem Solved


  • Subject: Re: Unarchiving Problem Solved
  • From: Craig Bakalian <email@hidden>
  • Date: Sun, 30 Mar 2003 03:22:07 -0500

Hi,
After testing for two days I found MY bug in my unarchiving function.
Yet, I still don't understand, if someone could explain why one works
and the other didn't work, I would be thankful. This one throws a
double free() , or malloc exception...

-(id)initWithCoder: (NSCoder *)coder
{
self = [super init];
[self setQuestionBody: [coder decodeObject]];
[self setOptionOne: [coder decodeObject]];
[self setOptionTwo: [coder decodeObject]];
[self setOptionThree: [coder decodeObject]];
[self setOptionFour: [coder decodeObject]];
[coder decodeValueOfObjCType: "d" at: &correctChoice];
//problem here!
return self;
}

-(void)encodeWithCoder: (NSCoder *)coder
{
[coder encodeObject: [self questionBody]];
[coder encodeObject: [self optionOne]];
[coder encodeObject: [self optionTwo]];
[coder encodeObject: [self optionThree]];
[coder encodeObject: [self optionFour]];
[coder encodeValueOfObjCType: "d" at: &correctChoice]; //problem
here!
}

This one below works...

-(id)initWithCoder: (NSCoder *)coder
{
self = [super init];
[self setQuestionBody: [coder decodeObject]];
[self setOptionOne: [coder decodeObject]];
[self setOptionTwo: [coder decodeObject]];
[self setOptionThree: [coder decodeObject]];
[self setOptionFour: [coder decodeObject]];
[coder decodeValueOfObjCType: @encode(unsigned) at: &correctChoice];
return self;
}

-(void)encodeWithCoder: (NSCoder *)coder
{
[coder encodeObject: [self questionBody]];
[coder encodeObject: [self optionOne]];
[coder encodeObject: [self optionTwo]];
[coder encodeObject: [self optionThree]];
[coder encodeObject: [self optionFour]];
[coder encodeValueOfObjCType: @encode(unsigned) at: &correctChoice];
}

I thought I could use the standard "d" for encodeValueOfObjCType, like
on page 217 of learning Cocoa there is an example that uses a float
with "f". I mean "d" - integer is a standard for C, right?



Craig Bakalian
www.eThinkingCap.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: How to detect whether a filename points to a text clipping?
  • Next by Date: Re: How to detect whether a filename points to a text clipping?
  • Previous by thread: Re: How to detect whether a filename points to a text clipping?
  • Next by thread: Re: Unarchiving Problem Solved
  • Index(es):
    • Date
    • Thread