iOS Developer Library

Developer

Foundation Framework Reference NSOutputStream Class Reference

Options
Deployment Target:

On This Page
Language:

NSOutputStream

The NSOutputStream class is a subclass of NSStream that provides write-only stream functionality. More...

Inheritance


Conforms To


Import Statement


import Foundation @import Foundation;

Availability


Available in iOS 2.0 and later.
  • Creates and returns an initialized output stream that will write stream data to memory.

    Declaration

    Swift

    class func outputStreamToMemory() -> Self!

    Objective-C

    + (instancetype)outputStreamToMemory

    Return Value

    An initialized output stream that will write stream data to memory.

    Discussion

    The stream must be opened before it can be used.

    You retrieve the contents of the memory stream by sending the message propertyForKey: to the receiver with an argument of NSStreamDataWrittenToMemoryStreamKey.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Creates and returns an initialized output stream that can write to a provided buffer.

    Declaration

    Objective-C

    + (instancetype)outputStreamToBuffer:(uint8_t *)buffer capacity:(NSUInteger)capacity

    Parameters

    buffer

    The buffer the output stream will write to.

    capacity

    The size of the buffer in bytes.

    Return Value

    An initialized output stream that can write to buffer.

    Discussion

    The stream must be opened before it can be used.

    When the number of bytes written to buffer has reached capacity, the stream’s streamStatus will return NSStreamStatusAtEnd.

    Import Statement

    Availability

    Available in iOS 2.0 and later.

  • Creates and returns an initialized output stream for writing to a specified file.

    Declaration

    Objective-C

    + (instancetype)outputStreamToFileAtPath:(NSString *)path append:(BOOL)shouldAppend

    Parameters

    path

    The path to the file the output stream will write to.

    shouldAppend

    YEStrue if newly written data should be appended to any existing file contents, NOfalse otherwise.

    Return Value

    An initialized output stream that can write to path.

    Discussion

    The stream must be opened before it can be used.

    Import Statement

    Availability

    Available in iOS 2.0 and later.

  • Creates and returns an initialized output stream for writing to a specified URL.

    Declaration

    Objective-C

    + (instancetype)outputStreamWithURL:(NSURL *)url append:(BOOL)shouldAppend

    Parameters

    url

    The URL to the file the output stream will write to.

    shouldAppend

    YEStrue if newly written data should be appended to any existing file contents, NOfalse otherwise.

    Return Value

    An initialized output stream that can write to url.

    Discussion

    The stream must be opened before it can be used.

    Import Statement

    Availability

    Available in iOS 4.0 and later.

  • init(toMemory:) initToMemory Designated Initializer

    Returns an initialized output stream that will write to memory.

    Declaration

    Swift

    init(toMemory toMemory: ())

    Objective-C

    - (instancetype)initToMemory

    Return Value

    An initialized output stream that will write stream data to memory.

    Discussion

    The stream must be opened before it can be used.

    The contents of the memory stream are retrieved by passing the constant NSStreamDataWrittenToMemoryStreamKey to propertyForKey:.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns an initialized output stream that can write to a provided buffer.

    Declaration

    Swift

    init(toBuffer buffer: UnsafeMutablePointer<UInt8>, capacity capacity: Int)

    Objective-C

    - (instancetype)initToBuffer:(uint8_t *)buffer capacity:(NSUInteger)capacity

    Parameters

    buffer

    The buffer the output stream will write to.

    capacity

    The size of the buffer in bytes.

    Return Value

    An initialized output stream that can write to buffer.

    Discussion

    The stream must be opened before it can be used.

    When the number of bytes written to buffer has reached capacity, the stream’s streamStatus will return NSStreamStatusAtEnd.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Returns an initialized output stream for writing to a specified file.

    Declaration

    Swift

    convenience init?(toFileAtPath path: String, append shouldAppend: Bool)

    Objective-C

    - (instancetype)initToFileAtPath:(NSString *)path append:(BOOL)shouldAppend

    Parameters

    path

    The path to the file the output stream will write to.

    shouldAppend

    YEStrue if newly written data should be appended to any existing file contents, NOfalse otherwise.

    Return Value

    An initialized output stream that can write to path.

    Discussion

    The stream must be opened before it can be used.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • init(URL:append:) initWithURL:append: Designated Initializer

    Returns an initialized output stream for writing to a specified URL.

    Declaration

    Swift

    init?(URL url: NSURL, append shouldAppend: Bool)

    Objective-C

    - (instancetype)initWithURL:(NSURL *)url append:(BOOL)shouldAppend

    Parameters

    url

    The URL to the file the output stream will write to.

    shouldAppend

    YEStrue if newly written data should be appended to any existing file contents, NOfalse otherwise.

    Return Value

    An initialized output stream that can write to url.

    Discussion

    The stream must be opened before it can be used.

    Import Statement

    import Foundation

    Availability

    Available in iOS 4.0 and later.

  • A boolean value that indicates whether the receiver can be written to. (read-only)

    Declaration

    Swift

    var hasSpaceAvailable: Bool { get }

    Objective-C

    @property(readonly) BOOL hasSpaceAvailable

    Discussion

    YEStrue if the receiver can be written to or if a write must be attempted in order to determine if space is available, NOfalse otherwise.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Writes the contents of a provided data buffer to the receiver.

    Declaration

    Swift

    func write(_ buffer: UnsafePointer<UInt8>, maxLength length: Int) -> Int

    Objective-C

    - (NSInteger)write:(const uint8_t *)buffer maxLength:(NSUInteger)length

    Parameters

    buffer

    The data to write.

    length

    The length of the data buffer, in bytes.

    Return Value

    The number of bytes actually written, or -1 if an error occurs. More information about the error can be obtained with streamError. If the receiver is a fixed-length stream and has reached its capacity, 0 is returned.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.