Mac Developer Library

Developer

Foundation Framework Reference NSPortMessage Class Reference

Options
Deployment Target:

On This Page
Language:

NSPortMessage

An NSPortMessage defines a low-level, operating system-independent type for inter-application (and inter-thread) messages. Port messages are used primarily by the distributed objects system. You should implement inter-application communication using distributed objects whenever possible and use NSPortMessage only when necessary. More...

Inheritance


Conforms To


Import Statement


import Foundation @import Foundation;

Availability


Available in OS X v10.0 and later.
  • Initializes a newly allocated NSPortMessage object to send given data on a given port and to receiver replies on another given port.

    Declaration

    Swift

    init(sendPort sendPort: NSPort, receivePort receivePort: NSPort, components components: [AnyObject])

    Objective-C

    - (instancetype)initWithSendPort:(NSPort *)sendPort receivePort:(NSPort *)receivePort components:(NSArray *)components

    Parameters

    sendPort

    The port on which the message is sent.

    receivePort

    The port on which replies to the message arrive.

    components

    The data to send in the message. components should contain only NSData and NSPort objects, and the contents of the NSData objects should be in network byte order.

    Return Value

    An NSPortMessage object initialized to send components on sendPort and to receiver replies on receivePort.

    Discussion

    An NSPortMessage object initialized with this method has a message identifier of 0.

    This is the designated initializer for NSPortMessage.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setMsgid:

  • Attempts to send the message before aDate, returning YEStrue if successful or NOfalse if the operation times out.

    Declaration

    Swift

    func sendBeforeDate(_ aDate: NSDate) -> Bool

    Objective-C

    - (BOOL)sendBeforeDate:(NSDate *)aDate

    Parameters

    aDate

    The instant before which the message should be sent.

    Return Value

    YEStrue if the operation is successful, otherwise NOfalse (for example, if the operation times out).

    Discussion

    If an error other than a time out occurs, this method could raise an NSInvalidSendPortException, NSInvalidReceivePortException, or an NSPortSendException, depending on the type of send port and the type of error.

    If the message cannot be sent immediately, the sending thread blocks until either the message is sent or aDate is reached. Sent messages are queued to minimize blocking, but failure can occur if multiple messages are sent to a port faster than the port’s owner can receive them, causing the queue to fill up. Therefore, select a value for aDate that provides enough time for the message to be processed before the next message is sent. See the NSPort class specification for information on receiving a port message.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Returns the data components of the receiver.

    Declaration

    Swift

    var components: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *components

    Return Value

    The data components of the receiver. See Class Description for more information.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • For an outgoing message, returns the port on which replies to the receiver will arrive. For an incoming message, returns the port the receiver did arrive on.

    Declaration

    Swift

    var receivePort: NSPort? { get }

    Objective-C

    @property(readonly, retain) NSPort *receivePort

    Return Value

    For an outgoing message, the port on which replies to the receiver will arrive. For an incoming message, the port the receiver did arrive on.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

    See Also

    – sendPort

  • For an outgoing message, returns the port the receiver will send itself through. For an incoming message, returns the port replies to the receiver should be sent through.

    Declaration

    Swift

    var sendPort: NSPort? { get }

    Objective-C

    @property(readonly, retain) NSPort *sendPort

    Return Value

    For an outgoing message, the port the receiver will send itself through when it receives a sendBeforeDate: message. For an incoming message, the port replies to the receiver should be sent through.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

    See Also

    – receivePort

  • Sets the identifier for the receiver.

    Declaration

    Swift

    var msgid: UInt32

    Objective-C

    @property uint32_t msgid

    Parameters

    msgid

    The identifier for the receiver.

    Discussion

    Cooperating applications can use this method to define different types of messages, such as connection requests, RPCs, errors, and so on.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

    See Also

    – msgid

  • Returns the identifier for the receiver.

    Declaration

    Swift

    var msgid: UInt32

    Objective-C

    @property uint32_t msgid

    Return Value

    The identifier for the receiver.

    Discussion

    Cooperating applications can use this to define different types of messages, such as connection requests, RPCs, errors, and so on.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

    See Also

    – setMsgid: