<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/KeyedEncodingContainer/encodeIfPresent(_:forKey:configuration:)-7x1yj",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s22KeyedEncodingContainerV10FoundationE15encodeIfPresent_6forKey13configurationyqd__Sg_xqd_0_mtKAC26EncodableWithConfigurationRd__AC0bM9ProvidingRd_0_0bM0Qyd_0_AJRtd__r0_lF"
  },
  "title" : "encodeIfPresent(_:forKey:configuration:)"
}
-->

# encodeIfPresent(_:forKey:configuration:)

```
mutating func encodeIfPresent<T, C>(_ t: T?, forKey key: KeyedEncodingContainer<K>.Key, configuration: C.Type) throws where T : EncodableWithConfiguration, C : EncodingConfigurationProviding, T.EncodingConfiguration == C.EncodingConfiguration
```

---

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)