Swift CMutablePointers in factories e.g. NewMusicSequence
- by Gene De Lisa
How do you use C level factory methods in Swift?
Let's try using a factory such as NewMusicSequence().
OSStatus status
var sequence:MusicSequence
status=NewMusicSequence(&sequence)
This errors out with "error: variable 'sequence' passed by reference before being initialized".
Set sequence to nil, and you get EXC_BAD_INSTRUCTION.
You can try being explicit like this:
var sp:CMutablePointer<MusicSequence>=nil
status=NewMusicSequence(sp)
But then you get a bad access exception when you set sp to nil. If you don't set sp, you get an "error: variable 'sp' used before being initialized"
Here's the reference.