Swift CMutablePointers in factories e.g. NewMusicSequence
Posted
by
Gene De Lisa
on Stack Overflow
See other posts from Stack Overflow
or by Gene De Lisa
Published on 2014-06-07T15:21:34Z
Indexed on
2014/06/07
15:24 UTC
Read the original article
Hit count: 285
swift-language
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.
© Stack Overflow or respective owner