# Not covered in book: Accessing TVML elements' views from Swift

**URL:** <https://forums.kodeco.com/t/not-covered-in-book-accessing-tvml-elements-views-from-swift/9470>\
**Category:** tvOS Apprentice\
**Created:** [March 13, 2016, 5:51pm UTC](https://forums.kodeco.com/t/not-covered-in-book-accessing-tvml-elements-views-from-swift/9470 "2016-03-13T17:51:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tommyb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tommyb/32/7707_2.png) [@tommyb](https://forums.kodeco.com/u/tommyb)\
**Post date:** [March 13, 2016, 5:51pm UTC](https://forums.kodeco.com/t/not-covered-in-book-accessing-tvml-elements-views-from-swift/9470/1 "2016-03-13T17:51:13Z")

</div>

The tvOS Apprentice book is really an outstanding title! However, there was something that I didn’t see covered in it and I haven’t found an answer to anywhere else.

I am showing a list of items using the TVML “Catalog” template. Users can delete items from the list, so I want to add a “shake” animation to a TVViewElement’s UIView when the user performs a “holdselect” action on it, like an app’s icon does when you’re about to delete it from the main Apple TV screen. I haven’t found built-in functionality that provides this behavior.

Based on what I learned from the tvOS Apprentice book, I think I need to call a Swift function from TVJS in response to the holdselect event being dispatched for a selected item. The Swift function will apply the animation to the selected item’s UIView. To do this, the UIView must be provided to it from TVJS or the UIView must be located given the selected TVViewElement. I don’t see a way to retrieve the UIView that is associated with a given TVViewElement.

Does anyone know how to do this? Feel free to suggest a different approach. Thanks!

---

<div class="post-metadata">

**Author:** ![tommyb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tommyb/32/7707_2.png) [@tommyb](https://forums.kodeco.com/u/tommyb)\
**Post date:** [March 14, 2016, 8:20pm UTC](https://forums.kodeco.com/t/not-covered-in-book-accessing-tvml-elements-views-from-swift/9470/2 "2016-03-14T20:20:53Z")

</div>

FYI, according to Apple Dev staff, there isn’t a built-in way of doing this.

Nurinder M  
Mar 14, 2016 9:58 AM

There isn’t any elegant way for you to acheive this using AppleTV constructed views. You would need to implement TVInterfaceCreating and create your own views and handle gestures on it.

---

<div class="post-metadata">

**Author:** ![samdavies](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/samdavies/32/111915_2.png) [@samdavies](https://forums.kodeco.com/u/samdavies)\
**Post date:** [March 16, 2016, 9:46am UTC](https://forums.kodeco.com/t/not-covered-in-book-accessing-tvml-elements-views-from-swift/9470/3 "2016-03-16T09:46:53Z")

</div>

Hi tommyb,

Sorry about the delay in my reply. I’m glad that my thoughts on the answer were backed up by Apple’s reply.

You could potentially override the generation of an Apple-based view and maintain some kind of lookup of native views and TVML elements, but I’m not sure about the viability of this approach without digging into it.

sam

---

<div class="post-metadata">

**Author:** ![tommyb](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/tommyb/32/7707_2.png) [@tommyb](https://forums.kodeco.com/u/tommyb)\
**Post date:** [March 16, 2016, 7:54pm UTC](https://forums.kodeco.com/t/not-covered-in-book-accessing-tvml-elements-views-from-swift/9470/4 "2016-03-16T19:54:52Z")

</div>

Thanks for the reply, Sam. I’m surprised that this wasn’t implemented “out of the box” yet. I expected the integration needed to allow shoring up TVML capabilities on the Swift side to be available.

It seems like going either direction, i.e., getting the TVViewElement associated with a UIView or vice versa, could be useful in a lot of situations where TVML **_almost_** does what you need.
