Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Table doesn't like my NSCalendarDate

Table doesn't like my NSCalendarDate
Thread Tools
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 11, 2002, 01:40 PM
 
I keep getting a signal 10 or a signal 11 when i try to load a table entry with an NSCalendarDate.

Here are the accessor methods for the NSCalendarDate:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
-(void) setArticleDateWithYear NSString *) aYear withMonth NSString *) aMonth withDay NSString *) aDay {

[aYear retain];
[aMonth retain];
[aDay retain];
[articleDate release];
articleDate=[NSCalendarDate dateWithYear:[aYear intValue] month:[aMonth intValue] day: [aDay intValue] hour:<font color = blue>0</font> minute:<font color = blue>0</font> second:<font color = blue>0</font> timeZone:[NSTimeZone timeZoneWithName:<font color = orange>@"PST"</font>]];
}
-(NSString *)articleDateString {

NSLog(<font color = orange>@"returning date"</font>);
return [articleDate descriptionWithCalendarFormat:<font color = orange>@"%m/%d/%y"</font>];

}
-(NSCalendarDate *)articleDate {
return articleDate;
}
</font>[/code]

The table column identifier is articleDateString. The table loads fine if I change the articleDateString method to:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
return <font color = orange>@"date"</font>;
</font>[/code]

So there is clearly something about returning the description of articleDate that is screwing it up. The funny thing is that I can use the articleDateString to print to the log right after setting articleDate.

Any ideas?

kman
     
kman42  (op)
Professional Poster
Join Date: Sep 2000
Location: San Francisco
Status: Offline
Reply With Quote
May 11, 2002, 01:56 PM
 
Originally posted by kman42:
<STRONG>I keep getting a signal 10 or a signal 11 when i try to load a table entry with an NSCalendarDate.

Here are the accessor methods for the NSCalendarDate:

&lt;BLOCKQUOTE&gt;&lt;font size="1"face="Geneva, Verdana, Arial"&gt;code:&lt;/font&gt;&lt;HR&gt;&lt;pre&gt;& amp;lt;font size=1 face=courier&gt;
-(void) setArticleDateWithYear NSString *) aYear withMonth NSString *) aMonth withDay NSString *) aDay {

[aYear retain];
[aMonth retain];
[aDay retain];
[articleDate release];
articleDate=[NSCalendarDate dateWithYear:[aYear intValue] month:[aMonth intValue] day: [aDay intValue] hour:&lt;font color = blue&gt;0&lt;/font&gt; minute:&lt;font color = blue&gt;0&lt;/font&gt; second:&lt;font color = blue&gt;0&lt;/font&gt; timeZone:[NSTimeZone timeZoneWithName:&lt;font color = orange&gt;@"PST"&lt;/font&gt;]];
}
-(NSString *)articleDateString {

NSLog(&lt;font color = orange&gt;@"returning date"&lt;/font&gt; );
return [articleDate descriptionWithCalendarFormat:&lt;font color = orange&gt;@"%m/%d/%y"&lt;/font&gt;];

}
-(NSCalendarDate *)articleDate {
return articleDate;
}
&lt;/font&gt;&lt;/pre&gt;&lt;HR&gt;&lt;/BLOCKQUOTE&gt;

The table column identifier is articleDateString. The table loads fine if I change the articleDateString method to:
&lt;BLOCKQUOTE&gt;&lt;font size="1"face="Geneva, Verdana, Arial"&gt;code:&lt;/font&gt;&lt;HR&gt;&lt;pre&gt;& amp;lt;font size=1 face=courier&gt;
return &lt;font color = orange&gt;@"date"&lt;/font&gt;;
&lt;/font&gt;&lt;/pre&gt;&lt;HR&gt;&lt;/BLOCKQUOTE&gt;

So there is clearly something about returning the description of articleDate that is screwing it up. The funny thing is that I can use the articleDateString to print to the log right after setting articleDate.

Any ideas?

kman</STRONG>

I put a retain at the beginning of articleDateString and it now works fine. I'm a little puzzled by this, however. Why do I need a retain in this method? The only place that I am releasing articleDate is in the set method. Don't I need a release there?

kman
     
Forum Regular
Join Date: Oct 2001
Location: Sweden
Status: Offline
Reply With Quote
May 11, 2002, 05:48 PM
 
Originally posted by kman42:
<STRONG>
-(void) setArticleDateWithYear NSString *) aYear withMonth NSString *) aMonth withDay NSString *) aDay {

[aYear retain];
[aMonth retain];
[aDay retain];
</STRONG>
No need to retain these just to ask them for their intValue. In fact this way you leak memory since you don't have a matching release for these three objects. Don't worry, the arguments to a method won't be deallocated while inside the method (inless you explicitly release them and their retain count goes to zero)

<STRONG>
[articleDate release];
articleDate=[NSCalendarDate dateWithYear:[aYear intValue] month:[aMonth intValue] day: [aDay intValue] hour:0 minute:&lt;0&lt;/font&gt; second:0 timeZone:[NSTimeZone timeZoneWithName:@"PST"]];
</STRONG>
dateWithYear... returns an autoreleased object, meaning that you have to retain it if you want to use it again after you've left this method. That is why your application crashes when you try to access the object later. A simple rule is that all methods with names like [NSDate dateWithYear...], [NSString stringWith...], [NSURL URLWith...], etc. returns autoreleased objects. If you create an object using [[NSString alloc] initWith...], [[NSDate alloc] initWiht...] etc. you'll get an object with a retain count of one, and no need to retain it to prevent it from going away. Don't forget to call release on theese objects though once you're done with them.

/Tobias
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:58 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2