---
title: "matchingFontDescriptor(withMandatoryKeys:)"
framework: appkit
role: symbol
role_heading: Instance Method
path: "appkit/nsfontdescriptor/matchingfontdescriptor(withmandatorykeys:)"
---

# matchingFontDescriptor(withMandatoryKeys:)

Returns a normalized font descriptor whose specified attributes match those of the receiver.

## Declaration

```swift
func matchingFontDescriptor(withMandatoryKeys mandatoryKeys: Set<NSFontDescriptor.AttributeName>?) -> NSFontDescriptor?
```

## Parameters

- `mandatoryKeys`: Keys that must be identical to be matched. Can be nil.

## Return Value

Return Value The matching font descriptor.  If there is no font that matches the given mandatory key values, returns nil.

## Discussion

Discussion If more than one font matches the [NSFontNameAttribute, NSFontFamilyAttribute, NSFontVisibleNameAttribute, NSFontFaceAttribute] attributes, the list of font descriptors is filtered by the other mandatory keys, if any, and the top result that is returned is the same as the first element returned from matchingFontDescriptors(withMandatoryKeys:). note: If only one font matches the [NSFontNameAttribute, NSFontFamilyAttribute, NSFontVisibleNameAttribute, NSFontFaceAttribute] attributes, the matchingFontDescriptorWithMandatoryKeys: function returns that font without further filtering for the other mandatory attributes. (This result differs from the result the matchingFontDescriptors(withMandatoryKeys:) function would return.) In other words, if there is exactly one match with the NSFontNameAttribute, NSFontFamilyAttribute, NSFontVisibleNameAttribute, NSFontFaceAttribute attributes, the matchingFontDescriptorWithMandatoryKeys: function always returns the font, even if the font doesn’t match the other mandatory keys.

## See Also

### Finding Fonts

- [matchingFontDescriptors(withMandatoryKeys:)](appkit/nsfontdescriptor/matchingfontdescriptors(withmandatorykeys:).md)
