You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See the <doc:#Pasted-Timecode-Validation-Against-Local-Context> section on how to validate pasted timecode.
91
+
92
+
> Important:
93
+
>
94
+
> If SwiftUI view modifiers using `NSItemProviders` are invoked without exporting `Timecode`'s UT Type, this error will be thrown:
95
+
>
96
+
> `Type "com.orchetect.TimecodeKit.timecode" was expected to be declared and exported in the Info.plist of MyApp.app, but it was not found.`
97
+
>
98
+
> See the <doc:#UT-Types> section for information on how to export this type in your app.
99
+
80
100
## Transferable
81
101
82
102
``Timecode`` conforms to the [`Transferable`](https://developer.apple.com/documentation/coretransferable/transferable) protocol which allows instances to be dragged & dropped or copied to/from the clipboard using declarative SwiftUI syntax.
See the <doc:#Pasted-Timecode-Validation-Against-Local-Context> section on how to validate pasted timecode.
143
+
117
144
> Important:
118
145
>
119
-
> If SwiftUI methods using the [`Transferable`](https://developer.apple.com/documentation/coretransferable/transferable) protocol are invoked without exporting this UT Type, this error will be thrown:
146
+
> If SwiftUI view modifiers using the [`Transferable`](https://developer.apple.com/documentation/coretransferable/transferable) protocol are invoked without exporting `Timecode`'s UT Type, this error will be thrown:
120
147
>
121
148
> `Type "com.orchetect.TimecodeKit.timecode" was expected to be declared and exported in the Info.plist of MyApp.app, but it was not found.`
122
149
>
123
-
> See UT Types section above for information on how to export this type in your app.
150
+
> See the <doc:#UT-Types> section for information on how to export this type in your app.
151
+
152
+
## Pasted Timecode Validation Against Local Context
153
+
154
+
When accepting timecode pasted from the clipboard, it is common to validate it against a local context.
155
+
156
+
For example, you may want to constrain pasted timecode to a certain frame rate, subframes base and upper limit.
157
+
158
+
`TimecodeKitUI` offers static API to perform this validation by supplying policies to validate against.
159
+
160
+
```swift
161
+
@TimecodeStateprivatevar timecode: Timecode
162
+
163
+
// pass in the `Timecode` instance received from the pasteboard
164
+
// from the `pasteDestination()` or `onPasteCommand()` view modifiers:
165
+
funcvalidate(pastedTimecode: Timecode) {
166
+
guardlet newTimecode = TimecodeField.validate(
167
+
pastedTimecode: pastedTimecode,
168
+
localTimecodeProperties: timecode.properties,
169
+
pastePolicy: .preserveLocalProperties,
170
+
validationPolicy: .enforceValid
171
+
) else { return }
172
+
173
+
timecode = newTimecode
174
+
}
175
+
```
176
+
177
+
> Note:
178
+
>
179
+
> This method is offered on `TimecodeField` since it is the same API the field uses internally when handling its own paste events.
180
+
>
181
+
> Because `TimecodeField` implements copy and paste functionality under the hood, calling the `validate` method is unnecessary as it is already being called internally on user paste events.
182
+
>
183
+
> Instead, use the corresponding view modifiers to specify the policies on your `TimecodeField` instance:
184
+
>
185
+
> -`timecodeFieldPastePolicy(_:)`
186
+
> -`timecodeFieldValidationPolicy(_:)`
187
+
> -`timecodeFieldInputStyle(_:)`
188
+
>
189
+
> See `TimecodeField` documentation in the `TimecodeKitUI` module for more information, or try out the **Timecode UI** example project located in the **Examples** folder within this repo.
0 commit comments