Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As the other poster pointed out, you are returning a CGPath reference taken from a UIBezierPath object that goes out of scope at the end of the method. As the docs on the UIBezierPath CGPath property say:</p> <blockquote> <p>The path object itself is owned by the UIBezierPath object and is valid only until you make further modifications to the path.</p> </blockquote> <p>You need to create a copy of your CGPath and return that:</p> <pre><code>-(CGPathRef)makeToPath { UIBezierPath* triangle = [UIBezierPath bezierPath]; [triangle moveToPoint:CGPointZero]; [triangle addLineToPoint:CGPointMake(self.view.frame.size.width,0)]; [triangle addLineToPoint:CGPointMake(0, self.view.frame.size.height)]; [triangle closePath]; CGPathRef theCGPath = [triangle CGPath]; return CGPathCreateCopy(theCGPath); } </code></pre> <p>The way I read the link to the llvm project, I think that the cf_returns_retained qualifier is intended to tell the caller the memory management policy for the returned value, rather than doing the retain for you. </p> <p>Thus I think you would both need to create a copy of the path AND add the cf_returns_retained qualifier. I'm not clear on the syntax of that qualifier, however. (Never used it before.)</p> <p>Assuming the other poster had the right syntax, it would look something like this:</p> <pre><code>-(CGPathRef)makeToPath CF_RETURNS_RETAINED; { UIBezierPath* triangle = [UIBezierPath bezierPath]; [triangle moveToPoint:CGPointZero]; [triangle addLineToPoint:CGPointMake(self.view.frame.size.width,0)]; [triangle addLineToPoint:CGPointMake(0, self.view.frame.size.height)]; [triangle closePath]; CGPathRef theCGPath = [triangle CGPath]; return CGPathCreateCopy(theCGPath); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload