I'm trying to write a String
to an NSOutputStream
in Swift. Writing Strings that way with Objective C usually works by passing it as NSData
NSData *data = [[NSData alloc] initWithData:[mystring dataUsingEncoding:NSASCIIStringEncoding]];
[outputStream write:[data bytes] maxLength:[data length]];
This does not work with swift
var data: NSData = mystring.dataUsingEncoding(NSUTF8StringEncoding)!
outputStream.write(data, maxLength: data.length)
this yields the error
'NSData' is not convertible to 'UnsafePointer'
for the line that writes the data to the stream.
How would you write a String to an NSOutputStream in Swift?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…