[swift-users] C API returns null but optional thinks it's set anyway

Rick Mann rmann at latencyzero.com
Fri Jul 1 02:59:10 CDT 2016

I have some Swift code (in Xcode 7.3) that's calling a C function in the GDAL library. It's declared like this:

typedef void *GDALDatasetH;
GDALOpen( const char *pszFilename, GDALAccess eAccess ) CPL_WARN_UNUSED_RESULT;

I'm calling it with code like this:

    func foo()
        self.dataset = GDALOpen(path, GA_ReadOnly)

    var dataset: GDALDatasetH?

But later code

    if let ds = self.dataset
        print("dataset: \(ds)")

outputs this to the console:

    dataset: 0x0000000000000000

This seems very broken.

Rick Mann
rmann at latencyzero.com

More information about the swift-users mailing list