I'm trying to write a
NSData *data = [[NSData alloc] initWithData:[mystring dataUsingEncoding:NSASCIIStringEncoding]];
[outputStream write:[data bytes] maxLength:[data length]];
var data: NSData = mystring.dataUsingEncoding(NSUTF8StringEncoding)!
outputStream.write(data, maxLength: data.length)
'NSData' is not convertible to 'UnsafePointer'
There are two issues here. The first is that you're passing
outputStream.write() and not
data.bytes (like you passed
[data bytes] in your Objective-C code). The second issue is that
data.bytes returns an
NSOutputStream.write() takes an
UnsafePointer has a way to convert between types:
/// Convert from a UnsafePointer of a different type. /// /// This is a fundamentally unsafe conversion. init<U>(_ from: UnsafePointer<U>)
Putting those things together makes your code look something like this:
let data: NSData = mystring.dataUsingEncoding(NSUTF8StringEncoding)! outputStream.write(UnsafePointer<UInt8>(data.bytes), maxLength: data.length)