NSString drawInRect set context

2019-06-04 05:47发布

问题:

I draw some image in background. Sometimes my app crashes with strange error:

function signature specialization < Arg[0] = Owned To Guaranteed> of MyApp.

I checked all crashes, and I get all of them on methods that do not use context. One of them draw text. How can I specify context to draw text?

UIGraphicsBeginImageContextWithOptions(size, false, 1.0)
let ctx = UIGraphicsGetCurrentContext()
// some code
str.drawInRect(CGRectMake(floor(10 * scaleFactor), yOffset, size.width, floor(60 * scaleFactor)), withAttributes: textFontAttributes)
// code
let img = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

Edit

I do not found any method to draw text in specific context. I use UIGraphicsPushContext(ctx) before draw text and UIGraphicsPopContext() after. https://stackoverflow.com/a/10402637/820795

回答1:

I'm not convinced that this has anything to do with drawing. The "function signature specialization" arises when there's a mistake in the Swift APIs where Objective-C needs to pass a nil parameter value to Swift, but the Swift version of this parameter is not typed as an Optional.