---
title: "url(relativeTo:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsurlcomponents/url(relativeto:)"
---

# url(relativeTo:)

Returns a URL object derived from the components object.

## Declaration

```swift
func url(relativeTo baseURL: URL?) -> URL?
```

## Parameters

- `baseURL`: If non-nil, this URL is used as the base URL portion of the resulting URL object.

## Discussion

Discussion If the components object has an authority component (user, password, host, or port) and a path component, then the path must either begin with "/" or be an empty string. Otherwise, this property contains nil. If the NSURLComponentsdoes not have an authority component (user, password, host, or port) and has a path component, the path component must not start with "//". If it does, this property contains nil. To configure a components object based on an existing URL, call either the componentsWithURL:resolvingAgainstBaseURL: or init(url:resolvingAgainstBaseURL:) method.

## See Also

### Getting the URL

- [string](foundation/nsurlcomponents/string.md)
- [url](foundation/nsurlcomponents/url.md)
