---
title: "value(forKey:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsorderedset/value(forkey:)"
---

# value(forKey:)

Returns an ordered set containing the results of invoking valueForKey: using key on each of the ordered set’s objects.

## Declaration

```swift
func value(forKey key: String) -> Any
```

## Parameters

- `key`: The key to retrieve.

## Return Value

Return Value The ordered set of the values for the retrieved key. The returned ordered set might not have the same number of members as the receiver.

## Discussion

Discussion The returned ordered set will not contain any elements corresponding to instances of valueForKey: returning nil, nor will it contain duplicates.

## See Also

### Key-Value Coding Support

- [setValue(_:forKey:)](foundation/nsorderedset/setvalue(_:forkey:).md)
