Checking if an UnsafeMutablePointer is NULL in Swift 3


(Vinicius Vendramini) #1

Hi all!

Used to be in Swift 2.x I only had to compare an unsafe pointer (obtained from a C API) to nil to know whether or not it was NULL. After conversion to Swift 3, it seems that isn’t allowed anymore.

I remember watching something about it in WWDC but I can’t remember (or find) the solution anymore. Can someone point me in the right direction?

Thanks a bunch :slight_smile:


(Dmitri Gribenko) #2

UnsafePointer<T> is not nullable anymore. 'UnsafePointer<T>?' is
nullable, like any optional.

Dmitri

···

On Tue, Jul 5, 2016 at 3:40 PM, Vinicius Vendramini via swift-users <swift-users@swift.org> wrote:

Hi all!

Used to be in Swift 2.x I only had to compare an unsafe pointer (obtained from a C API) to nil to know whether or not it was NULL. After conversion to Swift 3, it seems that isn’t allowed anymore.

I remember watching something about it in WWDC but I can’t remember (or find) the solution anymore. Can someone point me in the right direction?

--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/