An abstract class that represents a communication channel.
- iOS 2.0+
- macOS 10.0+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Communication occurs between
NSPort objects, which typically reside in different threads or tasks. The distributed objects system uses
NSPort objects to send
NSPort objects back and forth. Implement interapplication communication using distributed objects whenever possible and use
NSPort objects only when necessary.
NSPort 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 instance of
NSPort, 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
NSMessage allow local (on the same machine) communication only.
NSSocket 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.