# What's the meaning of?

**URL:** <https://forums.kodeco.com/t/whats-the-meaning-of/29512>\
**Category:** 2D iOS & tvOS Games by Tutorials\
**Created:** [May 10, 2017, 11:02am UTC](https://forums.kodeco.com/t/whats-the-meaning-of/29512 "2017-05-10T11:02:06Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nehemie](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@nehemie](https://forums.kodeco.com/u/nehemie)\
**Post date:** [May 10, 2017, 11:02am UTC](https://forums.kodeco.com/t/whats-the-meaning-of/29512/1 "2017-05-10T11:02:06Z")

</div>

Hi everyone ,

I am actually doing the tile map tutorial, I feel myself stuck with the meaning of a line in a method in the chapter 13: Intermediate Tile Maps page 364.

func tileGroupForName(tileSet: SKTileSet, name: String)  
 → SKTileGroup? {  
let tileGroup = tileSet.tileGroups  
.filter { $0.name == name }.first  
return tileGroup  
}

This method returns a named tile group within a tile set to replace a tile texture.

The line I don’t understand is :

let tileGroup = tileSet.tileGroups  
.filter { $0.name == name }.first

If anyone can help me pleaaaase 😢

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [May 10, 2017, 11:33am UTC](https://forums.kodeco.com/t/whats-the-meaning-of/29512/2 "2017-05-10T11:33:43Z")

</div>

@nehemie

```auto
let tileGroup = tileSet.tileGroups.filter { $0.name == name }.first

```

First we have `tileSet.tileGroups.filter {}`

Here you can specify a new array which consists of values specified within the closure.

You can experiment with this in a playground.

This more explicit code:

```
var array = [1, 2, 3, 4, 5, 1, 2]
let newArray = array.filter ( { value -> Bool in
  value == 1
})

```

in a playground will result in `newArray` being equal to `[1, 1]`

In the book’s code, `$0` is an inexplicit parameter. In the above code, `$0` is replaced by the explicit `value`.

The closure should contain an expression resulting in a boolean, which indicates whether the particular value being processed should survive the filter.

```
$0.name == name

```

asks whether each name value in the array is equal to the name variable.

The book’s code doesn’t create an array though. Appended to the filter closure is `.first`.

That just means that the first value in the new filtered array will be used, just in case there are more of them.

I hope that helps

---

<div class="post-metadata">

**Author:** ![nehemie](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@nehemie](https://forums.kodeco.com/u/nehemie)\
**Post date:** [May 11, 2017, 1:33am UTC](https://forums.kodeco.com/t/whats-the-meaning-of/29512/3 "2017-05-11T01:33:55Z")

</div>

Thanks Caroline for rescuing me again and sorry for the late answer, I live in Australia.

I do have some questions ,

1)Why do I have to use a filter and not just the User Data name straight away?

1. Is $0.name equal to tileGroups.name ?

3)Does .first represent the first tile of my tileGroups.name filtered ?

![](https://raywenderlich-com-v3-forums.s3.amazonaws.com/original/3X/8/c/8cda10848ce649c70101ff9df326bde5becf7c6b.png)

thanks again Caroline

---

<div class="post-metadata">

**Author:** ![caroline](https://assets.chunter.kodeco.com/user_avatar/forums.kodeco.com/caroline/32/111867_2.png) [@caroline](https://forums.kodeco.com/u/caroline)\
**Post date:** [May 11, 2017, 8:25pm UTC](https://forums.kodeco.com/t/whats-the-meaning-of/29512/4 "2017-05-11T20:25:15Z")

</div>

@nehemie - I’m usually in Australia, but am in England at the moment.

Going from the top:

`Obstacles` is the SKTileSet. Each SKTileSet has an array of SKTileGroups.

`[wall, wall-cracked, wall-broken]` is the array of SKTileGroups. Each SKTileGroup has an array of SKTileGroupRules.

`[Tile]` (under `wall-cracked` is the array of SKTileGroupRules. Each SKTileGroupRule has an array of SKTileDefinitions.

`[wall-cracked]` (under `wall-cracked->Tile`) is the array of SKTileDefinitions. A SKTileDefinition is the class that has the `userData` property.

So you need to go down quite a long way from the SKTileGroup to get to the `userData`.

`tileSet.tileGroups` returns `[wall, wall-cracked, wall-broken]`, so you need to filter out `wall-cracked` (for example).

```
tileSet.tileGroups.filter {
  $0.name == name
}

```

returns `[wall-cracked]` (when `name == “wall-cracked”`).

To get just `wall-cracked`, you need to get it out of the array, so `first` will get the first occurrence.

---

<div class="post-metadata">

**Author:** ![nehemie](https://s3.amazonaws.com/cdn.raywenderlich.com/community/forum-assets/noun-game-ghost-878668.png) [@nehemie](https://forums.kodeco.com/u/nehemie)\
**Post date:** [May 12, 2017, 5:20am UTC](https://forums.kodeco.com/t/whats-the-meaning-of/29512/5 "2017-05-12T05:20:55Z")

</div>

thank you very much for the helpful informations, I didn’t understand it was structured like that, I am going to read that chapter again 😅
