---
title: "encode(_:forKey:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nscoder/encode(_:forkey:)-6wbby"
---

# encode(_:forKey:)

Encodes a given Core Media time structure and associates it with a specified key.

## Declaration

```swift
func encode(_ time: CMTime, forKey key: String)
```

## Parameters

- `time`: A CMTime structure.
- `key`: The key with which to associate time in the archive.

## See Also

### Related Documentation

- [decodeTime(forKey:)](foundation/nscoder/decodetime(forkey:).md)

### Encoding Core Media Time Structures

- [encode(_:forKey:)](foundation/nscoder/encode(_:forkey:)-46lo8.md)
- [encode(_:forKey:)](foundation/nscoder/encode(_:forkey:)-8tefb.md)
