<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSURLQueryItem/init(name:value:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLQueryItem(im)initWithName:value:"
  },
  "title" : "init(name:value:)"
}
-->

# init(name:value:)

Initializes a newly allocated query item with the specified name and value.

```
init(name: String, value: String?)
```

## Parameters

`name`

The name of the query item. For example, in the URL `http://www.apple.com/search/?q=iPad`, the `name` parameter is `q`.

`value`

The value for the query item. For example, in the URL `http://www.apple.com/search/?q=iPad`, the `value` parameter is `iPad`.

## Return Value

An initialized query item object.

## Discussion

To use the newly initialized query item in composing a URL, add it to the [`queryItems`](/documentation/Foundation/NSURLComponents/queryItems) array of an [`NSURLComponents`](/documentation/Foundation/NSURLComponents) instance. Because assigning an array of query items to an [`NSURLComponents`](/documentation/Foundation/NSURLComponents) instance automatically encodes the name and value properties, you should not percent-encode these strings.

---

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)