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

# port

The port component of the URL if the URL conforms to RFC 3986; otherwise, nil.

## Declaration

```swift
var port: Int? { get }
```

## Discussion

Discussion note: This function resolves against the base URL.

## See Also

### Accessing the parts of a URL

- [fragment(percentEncoded:)](foundation/url/fragment(percentencoded:).md)
- [fragment](foundation/url/fragment.md)
- [host(percentEncoded:)](foundation/url/host(percentencoded:).md)
- [host](foundation/url/host.md)
- [lastPathComponent](foundation/url/lastpathcomponent.md)
- [path(percentEncoded:)](foundation/url/path(percentencoded:).md)
- [path](foundation/url/path.md)
- [password(percentEncoded:)](foundation/url/password(percentencoded:).md)
- [password](foundation/url/password.md)
- [pathComponents](foundation/url/pathcomponents.md)
- [pathExtension](foundation/url/pathextension.md)
- [query(percentEncoded:)](foundation/url/query(percentencoded:).md)
- [query](foundation/url/query.md)
- [scheme](foundation/url/scheme.md)
- [user(percentEncoded:)](foundation/url/user(percentencoded:).md)
