---
title: PortMessage
framework: foundation
role: symbol
role_heading: Class
path: foundation/portmessage
---

# PortMessage

A low-level, operating system-independent type for inter-application (and inter-thread) messages.

## Declaration

```swift
class PortMessage
```

## Overview

Overview Port messages are used primarily by the distributed objects system. You should implement inter-application communication using distributed objects whenever possible and use PortMessage only when necessary. An PortMessage object has three major parts: the send and receive ports, which are Port objects that link the sender of the message to the receiver, and the components, which form the body of the message. The components are held as an NSArray object containing NSData and Port objects. The send(before:) message sends the components out through the send port; any replies to the message arrive on the receive port. See the Port class specification for information on handling incoming messages. An PortMessage instance can be initialized with a pair of Port objects and an array of components. A port message’s body can contain only Port objects or NSData objects. In the distributed objects system the byte/character arrays are usually encoded NSInvocation objects that are being forwarded from a proxy to the corresponding real object. An PortMessage object also maintains a message identifier, which can be used to indicate the class of a message, such as an Objective-C method invocation, a connection request, an error, and so on. Use the msgid and msgid methods to access the identifier.

## Topics

### Creating Instances

- [init(send:receive:components:)](foundation/portmessage/init(send:receive:components:).md)

### Sending the Message

- [send(before:)](foundation/portmessage/send(before:).md)

### Getting the Components

- [components](foundation/portmessage/components.md)

### Getting the Ports

- [receivePort](foundation/portmessage/receiveport.md)
- [sendPort](foundation/portmessage/sendport.md)

### Accessing the Message ID

- [msgid](foundation/portmessage/msgid.md)

### Initializers

- [init(sendPort:receivePort:components:)](foundation/portmessage/init(sendport:receiveport:components:).md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Legacy

- [NSMachPortDelegate](foundation/nsmachportdelegate.md)
- [NSMachPort](foundation/nsmachport.md)
- [MessagePort](foundation/messageport.md)
- [PortDelegate](foundation/portdelegate.md)
- [NSProtocolChecker](foundation/nsprotocolchecker.md)
