I am trying to port working iPhone code to the Mac (iOS to OSX – I believe?)
The working iPhone version is
...
return [[UIColor alloc] initWithRed:r green:g blue:b alpha:1.0f];
}
The non-working Mac attempt is
...
return [NSColor colorWithCalibratedRed:r green:g blue:b alpha:1.0f];
}
But when I later access the container, the NSColor is not there. But when I try various versions of [NSColor alloc], none of them “work”.
My question is, how do I create an NSColor that persists (so that later, I have to de-allocate it)?
You need to retain your color in your mac attempt. You are calling a function that returns an autoreleased object. You need to either keep calling this function every time you want a color or do something like this: