# Dinodefense Ch19 Pathfinding: set\<GKEntity\> no sort

**URL:** <https://forums.kodeco.com/t/dinodefense-ch19-pathfinding-set-gkentity-no-sort/130943>\
**Category:** 2D iOS & tvOS Games by Tutorials\
**Created:** [January 24, 2021, 1:12pm UTC](https://forums.kodeco.com/t/dinodefense-ch19-pathfinding-set-gkentity-no-sort/130943 "2021-01-24T13:12:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wangying117](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/wangying117/32/81494_2.png) [@wangying117](https://forums.kodeco.com/u/wangying117)\
**Post date:** [January 24, 2021, 1:12pm UTC](https://forums.kodeco.com/t/dinodefense-ch19-pathfinding-set-gkentity-no-sort/130943/1 "2021-01-24T13:12:48Z")

</div>

Hello. DinoDefense coders,

During the challenge 2 in Chapter 19 Pathfinding, there is a piece of code which is used to sort all entities in the scene by y-position.

in GameScene.swift

> override func didFinishUpdate() {  
> …  
> // 1  
> let ySortedEntities = entities.sort {  
> let nodeA = $0.0.componentForClass(SpriteComponent.self)!.node  
> let nodeB = $0.1.componentForClass(SpriteComponent.self)!.node  
> return nodeA.position.y \> nodeB.position.y  
> }  
> }

There is an error in swift 4 or 5:

 ![截屏2021-01-24下午9.14.17](https://files.chunter.kodeco.com/original/3X/5/b/5b3f72fb0e02c7e2019328d5fe330922322476eb.png)

here is the definition of entities:

> var entities = Set\< GKEntity \>()

I’ve just checked the GKEntity and found only ‘sorted’ provided.  
the thing is ,however, I don’t know how to fix this problem.  
Anyone can help?  
Thanks.!

---

<div class="post-metadata">

**Author:** ![system](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@system](https://forums.kodeco.com/u/system)\
**Post date:** [July 10, 2021, 5:12am UTC](https://forums.kodeco.com/t/dinodefense-ch19-pathfinding-set-gkentity-no-sort/130943/2 "2021-07-10T05:12:50Z")

</div>

Closed on July 10, 2021, 5:12am UTC

This topic was automatically closed after 166 days. New replies are no longer allowed.
