<!--
{
  "availability" : [
    "iOS: 26.4.0 -",
    "iPadOS: 26.4.0 -",
    "macCatalyst: 26.4.0 -",
    "macOS: 26.4.0 -",
    "tvOS: 26.4.0 -",
    "visionOS: 26.4.0 -",
    "watchOS: 26.4.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Network",
  "identifier" : "/documentation/Network/NWEndpoint/init(copying:newPort:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Network"
    ],
    "preciseIdentifier" : "s:7Network10NWEndpointO7copying7newPortACSgAC_AC0E0Vtcfc"
  },
  "title" : "init(copying:newPort:)"
}
-->

# init(copying:newPort:)

Creates a new `NWEndpoint` by copying an existing endpoint and specifying a new port.

```
init?(copying endpoint: NWEndpoint, newPort: NWEndpoint.Port)
```

## Parameters

`endpoint`

The source endpoint to copy.

`newPort`

The new port to use.

## Return Value

A new `NWEndpoint` instance copied from the source endpoint with a new
port, or `nil` if the original endpoint is invalid or if modifying the port
for the copy results in an invalid endpoint. Examples of invalid endpoints are
malformed IP addresses or port numbers greater than 65535.

---

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)