An abstract class that represents a communication channel.
- iOS 2.0+
- macOS 10.0+
- tvOS 9.0+
- watchOS 2.0+
Communication occurs between
Port objects, which typically reside in different threads or tasks. The distributed objects system uses
Port objects to send
Port objects back and forth. Implement interapplication communication using distributed objects whenever possible and use
Port objects only when necessary.
Port object receives a port message, it forwards the message to its delegate in a
handle(_:) message. The delegate should implement only one of these methods to process the incoming message in whatever form desired.
handle provides a message as a raw Mach message beginning with a
handle(_:) provides a message as an
Port object, which is an object-oriented wrapper for a Mach message. If a delegate has not been set, the
NSPort object handles the message itself.
When you are finished using a port object, you must explicitly invalidate the port object prior to sending it a
release message. Similarly, if your application uses garbage collection, you must invalidate the port object before removing any strong references to it. If you do not invalidate the port, the resulting port object may linger and create a memory leak. To invalidate the port object, invoke its
Foundation defines three concrete subclasses of
Message allow local (on the same machine) communication only.
Socket allows for both local and remote communication, but may be more expensive than the others for the local case. When creating an
NSPort object, using
NSMach object is created instead.