advertisement

Article:
  Building a Scratch Pad with Cocoa
Subject:   got rid of warning with accessor and less self
Date:   2001-12-11 10:15:44
From:   psheldon
Response to: works but with warning (short code eg.)

I really don't know the meaning of "self" in newtonscript and objective C and need some years of pain, probably, to teach me the intuition and, beyond, perhaps to formalize into words. I think it is the left argument in the square brackets at first, be it class or instance.
When I tried to make a new version that used a ColorWell, all my plans went haywire, as I doubted I had understood memory managment deep in my bones. I threw in retains and releases and perhaps too many retains knowing that when I quit, it would clean house, maybe. Still no change of color. I think the click in the color well ran the mousedown method and I got messages about not having a point for a line as soon as I tried to draw. I got rid of those error messages, without understanding them really, by insuring that I last clicked on a button I called "Well" by putting code assigning a new path in the action associated with that button in padView.
So, having gotten rid of an error message, I went on to see that my color didn't change because my ColorBezier subclass of NSBezierpath didn't change. So, perhaps I don't know how to think in assigning currentPath because of this pointer retain and release stuff not having sunk in.
Perhaps the button and colorwell actions may illustrate my confusion rather than all my code :


- (IBAction)ChooseWell:(id)sender
{
[pathCurrent release];
pathCurrent = [ColorBezier initWithColor: colorCurrent];
[pathCurrent retain];
[ColorPaths addObject: pathCurrent];
}



- (IBAction)colorWellAction:(id)sender
{
float *locRed,*locGreen,*locBlue,*locAlpha;
[colorCurrent release];
colorCurrent = [sender color];
[colorCurrent retain];
//[colorCurrent getRed:locRed green:locGreen blue:locBlue alpha:locAlpha];
[colorCurrent set];
//[colorCurrent getRed:locRed green:locGreen blue:locBlue alpha:locAlpha];
}