---
title: queryItems
framework: foundation
role: symbol
role_heading: Instance Property
path: foundation/urlcomponents/queryitems
---

# queryItems

An array of query items for the URL in the order in which they appear in the original query string.

## Declaration

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

## Discussion

Discussion Each URLQueryItem represents a single key-value pair, Note that a name may appear more than once in a single query string, so the name values are not guaranteed to be unique. If the URLComponents has an empty query component, returns an empty array. If the URLComponents has no query component, returns nil. The setter combines an array containing any number of URLQueryItems, each of which represents a single key-value pair, into a query string and sets the URLComponents query property. Passing an empty array sets the query component of the URLComponents to an empty string. Passing nil removes the query component of the URLComponents. note: If a name-value pair in a query is empty (i.e. the query string starts with ‘&’, ends with ‘&’, or has “&&” within it), you get a URLQueryItem with a zero-length name and a nil value. If a query’s name-value pair has nothing before the equals sign, you get a zero-length name. If a query’s name-value pair has nothing after the equals sign, you get a zero-length value. If a query’s name-value pair has no equals sign, the query name-value pair string is the name and you get a nil value.

## See Also

### Accessing components in native format

- [fragment](foundation/urlcomponents/fragment.md)
- [host](foundation/urlcomponents/host.md)
- [encodedHost](foundation/urlcomponents/encodedhost.md)
- [password](foundation/urlcomponents/password.md)
- [path](foundation/urlcomponents/path.md)
- [port](foundation/urlcomponents/port.md)
- [query](foundation/urlcomponents/query.md)
- [scheme](foundation/urlcomponents/scheme.md)
- [user](foundation/urlcomponents/user.md)
