开发者

How to declare NSDAte in a Class And Assign value through Class Object(iphone Development)

I have Question related to nsdate declaration.

NSDate *sortDate;
@property(nonatomic,retain) NSDate *sortDate;
@synthesize sortDate;
sortDate=[NSDate date];

I assign NSdate field in my class with above Procedure.I successfully assign value to my NSDATE(sortarray).Whaen when i retrieve its value's App craches with this开发者_运维百科 message.

"malloc double free/non- aligned pointer being freed set a breakpoint in malloc_error_break to debug"

Give excess bad error.Some time it show,

When i remove NSDATE field from my class.App Run successfully.

Any thing wrong regarding declaration?

Any Solution.

Thanks in advance.


The date instance you get is autoreleased and not owned by you. If you assign directly to the ivar you have to take ownership, e.g.:

sortDate = [[NSDate date] retain];

It's usually better though to use the declared property, which takes care of that for you:

self.sortDate = [NSDate date];

Don't forget to relinquish ownership on dealloc, e.g.:

self.sortDate = nil;

See the Cocoa memory management rules and the declared properties documentation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜