2

I have been getting a swift build error.

func pathRefFromText() -> CGPathRef {

        let attributed : NSAttributedString = self.attrubutedText
        let line : CTLineRef = CTLineCreateWithAttributedString(attributed as! CFAttributedStringRef)
        let runArray : CFArrayRef = CTLineGetGlyphRuns(line)
        for var runIndex = 0; runIndex < CFArrayGetCount(runArray); runIndex++ {
            let run: CTRunRef = (CFArrayGetValueAtIndex(runArray, runIndex) as! CTRunRef)
           // let runFont : CTFontRef = CFDictionaryGetValue(CTRunGetAttributes(run), kCTFontAttributeName)
            for(var runGlyphIndex = 0; runGlyphIndex < CTRunGetGlyphCount(run); runGlyphIndex++)
            {
                let thisGlyphRange : CFRange = CFRangeMake(runGlyphIndex, 1)
                let glyph : CGGlyph!
                let position : CGPoint!

               // The build error comes in these two lines
                CTRunGetGlyphs(run, thisGlyphRange, glyph)
                CTRunGetPositions(run, thisGlyphRange, position)

            }
        }
    }

I get a build error saying Cannot convert value of type 'CGPoint!' to expected argument type 'UnsafeMutablePointer'

bneely
  • 9,083
  • 4
  • 38
  • 46
Aryan Kashyap
  • 157
  • 3
  • 11

1 Answers1

1

Try using:

var glyph : CGGlyph = CGGlyph()
var position : CGPoint = CGPoint()

CTRunGetGlyphs(run, thisGlyphRange, &glyph)
CTRunGetPositions(run, thisGlyphRange, &position)
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • Technically, this should probably be `var glyph: CGGlyph? = nil` (although `= nil` would be purely optional). The functions being called here haven't be updated with [nullability annotations](http://stackoverflow.com/a/29401454/2792531), but when & if it is, it'd surely be marked as taking an optional rather than a non-optional. The function certainly doesn't expect you to instantiate a value just for it to overwrite... – nhgrif Apr 07 '16 at 23:14