UnsafeMutablePointer<Int8> from String in Swift

Youssef Moawad picture Youssef Moawad · Jan 10, 2015 · Viewed 8.2k times · Source

I'm using the dgeev algorithm from the LAPACK implementation in the Accelerate framework to calculate eigenvectors and eigenvalues of a matrix. Sadly the LAPACK functions are not described in the Apple Documentation with a mere link to http://netlib.org/lapack/faq.html included.

If you look it up, you will find that the first two arguments in dgeev are characters signifying whether to calculate eigenvectors or not. In Swift, it is asking for UnsafeMutablePointer<Int8>. When I simply use "N", I get an error. The dgeev function and the error are described in the following screenshotenter image description here

What should I do to solve this?

Answer

D&#225;niel Nagy picture Dániel Nagy · Jan 10, 2015

It is ugly, but you can use:

let unsafePointerOfN = ("N" as NSString).UTF8String
var unsafeMutablePointerOfN: UnsafeMutablePointer<Int8> = UnsafeMutablePointer(unsafePointerOfN)

and use unsafeMutablePointerOfN as a parameter instead of "N".