<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSURLComponents/init(url:resolvingAgainstBaseURL:)-3bbte",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLComponents(im)initWithURL:resolvingAgainstBaseURL:"
  },
  "title" : "init(url:resolvingAgainstBaseURL:)"
}
-->

# init(url:resolvingAgainstBaseURL:)

Creates a URL components object by parsing the URL from an `NSURL` object.

```
init?(url: URL, resolvingAgainstBaseURL resolve: Bool)
```

## Parameters

`url`

The URL to parse.

`resolve`

Controls whether the URL should be resolved against its base URL before parsing. If <doc://com.apple.documentation/documentation/Swift/true>, and if the `url` parameter contains a relative URL, the original URL is resolved against its base URL before parsing by calling the [`absoluteURL`](/documentation/Foundation/NSURL/absoluteURL) method. Otherwise, the string portion is used by itself.

## Return Value

Returns the initialized URL components object, or `nil` if the URL could not be parsed.

---

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)