Search code examples
automatic-ref-countingcore-text

Retain a CTFrameRef property using ARC


Using ARC, how can I make sure a CTFrameRef property is not deallocated ? I am currently using an assign property, which is obviously not doing what I want


edit: my solution based on @KevinBallard answer :

- (void)setCoreTextFrame:(CTFrameRef)coreTextFrame
{
    _coreTextFrame = CFRetain(coreTextFrame);
}

- (void)dealloc
{
    CFRelease(_coreTextFrame);
}

Solution

  • CTFrameRef isn't an obj-c object. It follows the CoreFoundation memory management rules, so you can retain it with CFRetain() and release it with CFRelease().

    So basically, your code dealing with CTFrameRef will look identical to non-ARC code.