Swift cannot convert the expression's type 'Void' to type 'String!' -
i'm trying use piece of sample code this nshipster article, halfway down page.
var inputstream: nsinputstream var outputstream: nsoutputstream nsstream.getstreamstohostwithname(hostname: "nshipster.com", port: 5432, inputstream: &inputstream, outputstream: &outputstream)
i've placed in playground, along import foundation
, , error.
playground execution failed: error: <repl>:6:10: error: cannot convert expression's type 'void' type 'string!' nsstream.getstreamstohostwithname(hostname: "nshipster.com", ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
this error pointing first argument, of type string!
, not void
.
i changed code bit, extract definitions method call. here's complete playground:
import foundation var inputstream: nsinputstream var outputstream: nsoutputstream let host = "nshipster.com" let port = 5432 nsstream.getstreamstohostwithname(hostname: host, port: port, inputstream: &inputstream, outputstream: &outputstream)
now error indicates third argument, presumably happy first two.
playground execution failed: error: <repl>:10:18: error: cannot convert expression's type 'void' type 'inout nsinputstream' inputstream: &inputstream, ^~~~~~~~~~~~
i can't figure out how can extract autoreleasingunsafepointer
variables inputstream , outputstream in same manner, think original sample code should work. bug in (and mattt's) code, or bug in swift?
edit: i've submitted pull request corrected code nshipster.
well, short answer need passing in optionals instead of non-optionals (to that's looking inout objects)
var inputstream:nsinputstream? var outputstream:nsoutputstream? nsstream.getstreamstohostwithname("nshipster.com", port: 5432, inputstream: &inputstream, outputstream: &outputstream)
that said, compiles now, doesn't run because nsstream apparently doesn't have getstreamstohostwithname method (at least in foundation imported) never mind this, it's ios-only call, didn't work playground set osx. seems ok set ios.
Comments
Post a Comment