Could you please explain me how do I read properly from an NSInputStream?
I couldn't understand what is UnsafePointer and what's the use of it (also for UnsafeArray).
The NSInputStream read function gets an CMutablePointer which can be filled with an UnsafePointer object.
It's a real mess comparing to Java's Streams.
What would you recommend ?
Thank you!
I have figured it out myself.
Look at this simple code:
Explanation: The read method signature: stream.read(<#buffer: UnsafeMutablePointer#>, maxLength: <#Int#>)
It gets a UnsafeMutablePointer as a first parameter, which means the method expects to get a POINTER to an array of type UInt8 - NOT the array itself
Therefore, we add the & notation before the name of the buffer variable. &buffer == the pointer to the UInt8 array object named buffer.