Contents

CVAttachmentValueRepresentable

Allows Swift types to be used as buffer attachment value.

Declaration

protocol CVAttachmentValueRepresentable

Overview

A type conforming to this protocol can be used as value for an attachment key. The CVAttachmentRawValue type facilitates conversion to and from raw attachment values. Conformances of standard Swift type to this protocol are provided in CoreVideo framework. Implementing this protocol for a custom struct is as simple as:

struct MyStruct {
	var number: Int
	var tags: [String]
}

extension MyStruct: CVAttachmentValueRepresentable {
	static func makeFromRawAttachmentValue(_ repr: CVAttachmentRawValue) -> Self? {
		guard let number: Int = repr["number"], tags: [String] = repr["tags"] else { return nil }
		return .init(number: number, tags: tags)
	}

	var rawAttachmentValueRepresentation: CVAttachmentRawValue {
		["number": self.number, "tags": self.tags]
	}
}

Default implementation is provided for RawRepresentable protocol where RawValue conforms to this protocol. This allow enumeration with raw values to conform to CVAttachmentValueRepresentable protocol without a custom implementation.

Topics

Instance Properties

Type Methods

See Also

Protocols