Swift: Little things that still drive me nuts

UIGraphicsGetCurrentContext() should either throws or be optional. It isn’t. It’s func UIGraphicsGetCurrentContext() -> CGContext.

Screen Shot 2015-06-22 at 4.56.45 PM

So right now when I either try or if let, I can’t. I can’t even if context == nil, which means I have a lot of code I need to annotate with TODO and hope that I remember to come back to it.

For now, I’m just assuming the value returned is valid:

/// Perform a drawing transaction without 
/// affecting general graphics state
public func PushDraw(block: () -> Void) {
    let context = UIGraphicsGetCurrentContext()
    CGContextSaveGState(context)
    block()
    CGContextRestoreGState(context)
}

21494444

Comments are closed.