<!--
{
  "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/NSURLComponents/queryItems",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSURLComponents(py)queryItems"
  },
  "title" : "queryItems"
}
-->

# queryItems

The query URL component as an array of name/value pairs.

```
var queryItems: [URLQueryItem]? { get set }
```

## Discussion

When you get this property’s value, the [`NSURLComponents`](/documentation/Foundation/NSURLComponents) class parses the [`query`](/documentation/Foundation/NSURLComponents/query) string and returns an array of [`NSURLQueryItem`](/documentation/Foundation/NSURLQueryItem) objects, each of which represents a single key-value pair, in the order in which they appear in the original query string. Because a name may appear more than once in a single query string, the [`name`](/documentation/Foundation/NSURLQueryItem/name) properties of query items are not guaranteed to be unique. If the [`query`](/documentation/Foundation/NSURLComponents/query) property is an empty string, the [`queryItems`](/documentation/Foundation/NSURLComponents/queryItems) property is an empty array. If the [`query`](/documentation/Foundation/NSURLComponents/query) property is `nil`, the [`queryItems`](/documentation/Foundation/NSURLComponents/queryItems) property is also `nil`.

When you set this property’s value, the [`NSURLComponents`](/documentation/Foundation/NSURLComponents) class joins each name/value pair with a `=` delimiter and joins the array with a `&` delimiter, then sets the [`query`](/documentation/Foundation/NSURLComponents/query) property to the resulting string. Setting the [`queryItems`](/documentation/Foundation/NSURLComponents/queryItems) property to an empty array sets the [`query`](/documentation/Foundation/NSURLComponents/query) property to an empty string, and setting the [`queryItems`](/documentation/Foundation/NSURLComponents/queryItems) property to `nil` sets the [`query`](/documentation/Foundation/NSURLComponents/query) property to `nil`.

> Note:
> [RFC 3986](https://www.ietf.org/rfc/rfc3986.txt) specifies which characters must be percent-encoded in the query component of a URL, but not how those characters should be interpreted. The use of delimited key-value pairs is a common convention, but isn’t standardized by a specification. Therefore, you may encounter interoperability problems with other implementations that follow this convention.
> 
> One notable example of potential interoperability problems is how the plus sign (`+`) character is handled:
> 
> According to RFC 3986, the plus sign is a valid character within a query, and doesn’t need to be percent-encoded. However, according to the [W3C recommendations for URI addressing](https://www.w3.org/Addressing/URL/4_URI_Recommentations.html), the plus sign is reserved as shorthand notation for a space within a query string (for example, `?greeting=hello+world`).
> 
> If a URL query component contains a date formatted according to [RFC 3339](https://www.ietf.org/rfc/rfc3339.txt) with a plus sign in the timezone offset (for example, `2013-12-31T14:00:00+00:00`), interpreting the plus sign as a space results in an invalid time format. RFC 3339 specifies how dates should be formatted, but doesn’t advise whether the plus sign must be percent-encoded in a URL. Depending on the implementation receiving this URL, you may need to preemptively percent-encode the plus sign character.
> 
> As an alternative, consider encoding complex and/or potentially problematic data in a more robust data-interchange format, such as JSON or XML.

To ensure you can compose and decompose URL queries even with empty components, the [`NSURLComponents`](/documentation/Foundation/NSURLComponents) class has the following behavior for cases where no name or value is present:

- If a name-value pair has nothing before its equals sign, the `name` property of the corresponding query item is a zero-length string.
- If a name-value pair has nothing after its equals sign, the `value` property of the corresponding query item is a zero-length string.
- If a name-value pair has no equals sign, the `value` property of the corresponding query item is `nil`.
- If a name-value pair is empty (that is, the `query` string starts with `&`, ends with `&`, or contains `&``&`), the corresponding query item has a zero-length `name` and `nil` `value`.

For example, in the URL `http://www.example.com/index.php?key1=value1&key2=value2`, this property’s value is an array of two [`NSURLQueryItem`](/documentation/Foundation/NSURLQueryItem) objects: one whose name property is `key1` and whose value property is `value1`, and one whose name property is `key2` and whose value property is `value2`.

---

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)