<!--
{
  "availability" : [
    "macOS: 10.5.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AppKit",
  "identifier" : "/documentation/AppKit/NSFontDescriptor/matchingFontDescriptor(withMandatoryKeys:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AppKit"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFontDescriptor(im)matchingFontDescriptorWithMandatoryKeys:"
  },
  "title" : "matchingFontDescriptor(withMandatoryKeys:)"
}
-->

# matchingFontDescriptor(withMandatoryKeys:)

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

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

## Parameters

`mandatoryKeys`

Keys that must be identical to be matched. Can be `nil`.

## Return Value

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

## 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:)`](/documentation/AppKit/NSFontDescriptor/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 ``doc://com.apple.appkit/documentation/AppKit/NSFontDescriptor/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.

---

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)