Re: new class
Re: new class
- Subject: Re: new class
- From: "Shawn Erickson" <email@hidden>
- Date: Thu, 20 Sep 2007 18:59:32 -0700
On 9/20/07, PGM <email@hidden> wrote:
> > In a new class (subclass of NSObject) I have the following method:
> >
> > - (DCPoint)convert { // gives this error: can not use an object
> > as parameter to a method
> > DCPoint * DC = [[DCPoint alloc] init];
> >
> > // insert calculations here
> >
> > [DC initWithDistance:0 Course:0];
> > return DC; // gives this error: incompatible types in return
> >
> > }
>
> Also note that you init DC twice, but alloc it only once. In
> general, init should always be used concertedly with alloc. The line
> before the return should most likely be divided into two lines where
> you use setters to change the variables of DC:
>
> [DC setDistance:0];
> [DC setCourse:0];
...and you are leaking the DCPoint instance that gets allocated (not
following the Cocoa memory "contract").
-Shawn
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden