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

Brent Royal-Gordon brent at architechies.com
Sat Jul 2 01:02:16 CDT 2016

> On Jul 1, 2016, at 1:55 PM, Rick Mann via swift-users <swift-users at swift.org> wrote:
> typealias GDALDatasetH = UnsafeMutablePointer<Void>
> @warn_unused_result func GDALOpen(pszFilename: UnsafePointer<Int8>, _ eAccess: GDALAccess) -> GDALDatasetH
> Thanks for the clarification. It sure seems like Swift could easily check for Unsafe Pointers with value == 0.

In Swift 2, pointers are permitted to be `nil` even if they're not `Optional`. Swift 3 changes this, and so this parameter would either return `GDALDatasetH?` or, if it hadn't been audited yet, `GDALDatasetH!`.

Brent Royal-Gordon

More information about the swift-users mailing list