# Tree Deserialize solution bug

**URL:** <https://forums.kodeco.com/t/tree-deserialize-solution-bug/70861>\
**Category:** Data Structures & Algorithms in Swift\
**Created:** [May 14, 2019, 4:51pm UTC](https://forums.kodeco.com/t/tree-deserialize-solution-bug/70861 "2019-05-14T16:51:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oaranger](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/oaranger/32/106437_2.png) [@oaranger](https://forums.kodeco.com/u/oaranger)\
**Post date:** [May 14, 2019, 4:51pm UTC](https://forums.kodeco.com/t/tree-deserialize-solution-bug/70861/1 "2019-05-14T16:51:24Z")

</div>

Hello,

On page 339, solution for deserialize the tree need extra condition

// 2  
guard let value = array.removeFirst() else {

should be changed to:  
// 2  
guard !array.isEmpty, let value = array.removeFirst() else {

Otherwise it results in error “Can’t remove first element from empty collection”

Best,

---

<div class="post-metadata">

**Author:** ![shogunkaramazov](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/shogunkaramazov/32/108826_2.png) [@shogunkaramazov](https://forums.kodeco.com/u/shogunkaramazov)\
**Post date:** [July 9, 2019, 2:28am UTC](https://forums.kodeco.com/t/tree-deserialize-solution-bug/70861/2 "2019-07-09T02:28:21Z")

</div>

@oaranger Thank you for your solution - much appreciated! We will definitely fix this in the next version of the book.

---

<div class="post-metadata">

**Author:** ![kelvin\_lau](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/kelvin_lau/32/109371_2.png) [@kelvin\_lau](https://forums.kodeco.com/u/kelvin_lau)\
**Post date:** [August 5, 2019, 7:28pm UTC](https://forums.kodeco.com/t/tree-deserialize-solution-bug/70861/3 "2019-08-05T19:28:47Z")

</div>

This will be resolved in the next release! Thanks for reporting
