Monday, 15 August 2011

core text - Issue with CoreText CTFrameGetLineOrigins in Swift -



core text - Issue with CoreText CTFrameGetLineOrigins in Swift -

i have next code working in objective-c

nsarray *lines = (nsarray *)ctframegetlines((__bridge ctframeref)columnframe); cgpoint origins[[lines count]]; ctframegetlineorigins((__bridge ctframeref)columnframe, cfrangemake(0, 0), origins);

but when ported swift, compiler complains cannot convert expression´s ´void´to type ´cmutablepointer<cgpoint> in ctframegetlineorigins line

let nslinesarray: nsarray = ctframegetlines(ctframe) // utilize nsarray bridge array allow ctlinesarray = nslinesarray array var originsarray: array<cgpoint> = cgpoint[]() //var originsarray: nsmutablearray = nsmutablearray.array() allow range: cfrange = cfrangemake(0, 0) ctframegetlineorigins(ctframe, range, originsarray)

i had utilize nsarray in cgframegetlines function, , convert swift array, , inspecting ctlinesarray, shows ctline objects retrieved correctly

i tried using nsmutablearray originsarray, same result.

any thought of missing?

you have add together address-of operator & pass pointer start of originsarray function:

ctframegetlineorigins(ctframe, range, &originsarray)

reference: interacting c apis in "using swift cocoa , objective-c" book:

c mutable pointers

when function declared taking cmutablepointer<type> argument, can take of following:

... an in-out type[] value, passed pointer start of array, , lifetime-extended duration of call.

and expressions in "the swift programming language" book:

in add-on standard library operators listed above, utilize & before name of variable that’s beingness passed in-out argument function phone call expression.

an add-on (as @eharo2 figured out), originsarray must have room necessary number of elements, can achieved with

var originsarray = cgpoint[](count:ctlinesarray.count, repeatedvalue: cgpointzero)

swift core-text

No comments:

Post a Comment