Swift CMutablePointers in factories e.g. NewMusicSequence -
how use c level factory methods in swift?
let's try using factory such newmusicsequence().
var status:osstatus var sequence:musicsequence status=newmusicsequence(&sequence)
this errors out "error: variable 'sequence' passed reference before being initialized". set sequence nil, , exc_bad_instruction.
you can try being explicit this:
var sp:cmutablepointer<musicsequence>=nil status=newmusicsequence(sp)
but bad access exception when set sp nil. if don't set sp, "error: variable 'sp' used before being initialized"
i'd expect way it, it's not:
import audiotoolbox var sequence: musicsequence? var status:osstatus = newmusicsequence(&sequence)
error: cannot convert expression's type 'osstatus' type 'inout musicsequence?' var status:osstatus = newmusicsequence(&sequence)
here's reference.
i think issue need optional value. optional values initialized nil
, optional values can ever nil
.
var sequence: musicsequence? let status = newmusicsequence(&sequence)
Comments
Post a Comment