CGContext text drawing in Swift 3

I can't figure out how to draw a text string in a CGContext. According to the documentation, every method that has a string parameter has been deprecated. But CGContext still has a textPosition property.

Replies

Drawing text with CG is almost never the right option. For this reason, routines like

CGContextShowGlyphs
have been deprecated in Objective-C and aren’t available in Swift. The only exception is
CGContextShowGlyphsAtPositions
, but even that’s imported into Swift with a double underscore prefix (
__showGlyphs(_:atPositions:count:)
). The recommended alternative is Core Text.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

After much googling I finally got this from some example code:


myString.draw(at: CGPoint(x: 0, y: lineOffset), withAttributes: [:])


Where would I look for these methods in the documentation? What API are they from?

I found the documentation, under NSString in Foundation. I was sure it would be in UIKit somewhere.