use CFDataGetBytePtr to get image bytes, but it crashes

My code is as follow:

let img = UIImage(named: "in00c.png")
guard let data = CFDataGetBytePtr(img!.cgImage!.dataProvider!.data) else {
          fatalError("Couldn't access image data")
        }
print(data[0])

it crashes at last line print(data[0]), due to EXC_BAD_ACCESS (code=1, address=0x1074e8000)

Does I have something wrong with the code? I am using the latest Xcode, seems it works ok in previous versions.

Plus, it works ok in simulator, but crashes on device

Did you find a solution? I stumbled exactly the same problem :(

use CFDataGetBytePtr to get image bytes, but it crashes
 
 
Q