1
var readStream:CFReadStream?
var writeStream:CFWriteStream?
var request: NSMutableURLRequest = NSMutableURLRequest()

var host = request.URL.host
var port = request.URL.port.unsignedIntegerValue

CFStreamCreatePairWithSocketToHost(nil, nil, port, readStream, writeStream)
^ "Cannot convert the expression's type Void to type CFAllocator!"

Why is it assuming I am changing it's type to 'CFAllocator!'. I tried changing the input values, but it keeps coming up with the same error.

Chris
  • 1,416
  • 18
  • 29

1 Answers1

1

Figured it out.

var host: CFString = NSString(string: request.URL.host)
var port: UInt32 =  UInt32(request.URL.port.unsignedIntegerValue)

var readStream: Unmanaged<CFReadStream>?
var writeStream: Unmanaged<CFWriteStream>?

CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, host, port, &readStream, &writeStream)

inputStream = readStream!.takeUnretainedValue()
outputStream = writeStream!.takeUnretainedValue()

inputStream!.delegate = self
outputStream!.delegate = self

inputStream!.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)
outputStream!.scheduleInRunLoop(NSRunLoop.currentRunLoop(), forMode: NSDefaultRunLoopMode)

inputStream!.open()
outputStream!.open()

The reason this error comes up is because all the values have to be the exact type the "CreatePairWithSocket.." function is asking for. I did some research and also found this very helpful question.

Community
  • 1
  • 1