<!--
{
  "availability" : [
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.0.0 - 10.13.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSPortCoder/encodePortObject:",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSPortCoder(im)encodePortObject:"
  },
  "title" : "encodePortObject:"
}
-->

# encodePortObject:

Encodes a given port so it can be properly reconstituted in the receiving process or thread.

```
- (void) encodePortObject:(NSPort *) aport;
```

## Parameters

`aport`

The port to encode.

## Discussion

This method is primarily for use by `NSPort` objects themselves—you can always use the general `encode...Object:` methods to encode any object.

`NSPort` invokes this method in its [`encode(with:)`](/documentation/Foundation/NSCoding/encode(with:)) method so that the appropriate kernel information for the port can be encoded. A subclass of `NSPortCoder` should not encode an `NSPort` by sending it an [`encode(with:)`](/documentation/Foundation/NSCoding/encode(with:)) message. See [Subclassing NSCoder](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Archiving/Articles/subclassing.html#//apple_ref/doc/uid/20000951) for more information.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)