---
title: port
framework: foundation
role: symbol
role_heading: Instance Property
path: foundation/nsurlcomponents/port
---

# port

The port number URL component, or nil if not present.

## Declaration

```swift
@NSCopying var port: NSNumber? { get set }
```

## Discussion

Discussion For example, in the URL http://www.example.com:8080/index.php, the port number is 8080. If you attempt to set the port to a negative port number, this class throws an exception.

## See Also

### Accessing components in native format

- [fragment](foundation/nsurlcomponents/fragment.md)
- [host](foundation/nsurlcomponents/host.md)
- [encodedHost](foundation/nsurlcomponents/encodedhost.md)
- [password](foundation/nsurlcomponents/password.md)
- [path](foundation/nsurlcomponents/path.md)
- [query](foundation/nsurlcomponents/query.md)
- [queryItems](foundation/nsurlcomponents/queryitems.md)
- [scheme](foundation/nsurlcomponents/scheme.md)
- [user](foundation/nsurlcomponents/user.md)
