Ser Pounce
Ser Pounce

Reputation: 14553

Having trouble retaining a CGPath object (warning appears)

I have an instance variable CGMutablePathRef _mutablePath which I set as @property (nonatomic) CGMutablePathRef mutablePath; . I override the setter method:

- (void) setMutablePath:(CGMutablePathRef)mutablePath
{
    if (_mutablePath)
    {
        CGPathRelease(_mutablePath);
        _mutablePath = NULL;
    }

    _mutablePath = CGPathRetain(mutablePath);
}

However I am getting a warning on this line: _mutablePath = CGPathRetain(mutablePath); that says:

Assigning to 'CGMutablePathRef' (aka 'struct CGPath *') from 'CGPathRef' (aka 'const struct CGPath *') discards qualifiers

Why would this not work? This seems to work with CT (core text) objects when I do it. I've tried a bunch of different casts but can't get the error to go away, any advice would be appreciated.

Upvotes: 1

Views: 982

Answers (1)

Lily Ballard
Lily Ballard

Reputation: 185681

CGPathRetain() is declared as

CGPathRef CGPathRetain(CGPathRef path);

This means it returns a CGPathRef instead of a CGMutablePathRef. You should cast the result back to CGMutablePathRef before assigning it to your _mutablePath ivar.

Upvotes: 3

Related Questions