Swift Playground - Map and Filter Steemit.Inc employees by tarekadam

View this thread on steempeak.com
· @tarekadam ·
$0.27
Swift Playground - Map and Filter Steemit.Inc employees
Let's start by creating a model data template with **name** and **role** for the Steemit Inc employees using a [Struct](https://docs.swift.org/swift-book/LanguageGuide/ClassesAndStructures.html). 

```
struct Employee {
    let name: String
    let role: String
}
```

Now lets create an [Array](https://docs.swift.org/swift-book/LanguageGuide/CollectionTypes.html)  that holds a few of the Steemit.INC (ex)employees .

```
let steemitInc = [
Employee(name: "Ned", role: "ex-CEO"),
Employee(name: "Vandeberg", role: "Blockchain Developer"),
Employee(name: "Justin", role: "Head of Engineering"),
Employee(name: "roadscape", role: "Senior Product Engineer")
]
```

To extract all roles from that **steemitInc** Array we can use the [map](https://developer.apple.com/documentation/swift/array/3017522-map) method in Swift to put all roles into a new array.

`var searchRole = steemitInc.map { $0.role } `

Finally, having extracted the roles we can now **find** a user tied to that role using the [filter](https://developer.apple.com/documentation/swift/sequence/3018365-filter) method.

`var findUser = steemitInc.filter { $0.role == "ex-CEO"}`

## The complete Swift Playground looks like this:

<center>
![Swift Map and Filter.png](https://cdn.steemitimages.com/DQmWoMunRgmijASTqBPrMYra13Upp5wbwy12GA2ArzcHXsJ/Swift%20Map%20and%20Filter.png)
</center>


Hopefully you find this little tutorial useful. I linked most of the topics covered to the Apple documentation for further reading.
👍  , , , , , , , , , , , , , , , , , ,
👎  ,
properties (23)
post_id84,640,977
authortarekadam
permlinkswift-playground-map-and-filter-steemit-inc-employees
categoryhive-168180
json_metadata{"tags":["tutorial","swift","programming"],"image":["https:\/\/cdn.steemitimages.com\/DQmWoMunRgmijASTqBPrMYra13Upp5wbwy12GA2ArzcHXsJ\/Swift%20Map%20and%20Filter.png"],"links":["https:\/\/docs.swift.org\/swift-book\/LanguageGuide\/ClassesAndStructures.html","https:\/\/docs.swift.org\/swift-book\/LanguageGuide\/CollectionTypes.html","https:\/\/developer.apple.com\/documentation\/swift\/array\/3017522-map","https:\/\/developer.apple.com\/documentation\/swift\/sequence\/3018365-filter"],"app":"steemit\/0.2","format":"markdown"}
created2020-02-23 06:09:00
last_update2020-02-23 06:09:00
depth0
children0
net_rshares1,480,329,126,165
last_payout2020-03-01 06:09:00
cashout_time1969-12-31 23:59:59
total_payout_value0.135 SBD
curator_payout_value0.130 SBD
pending_payout_value0.000 SBD
promoted0.000 SBD
body_length1,486
author_reputation48,977,881,936,844
root_title"Swift Playground - Map and Filter Steemit.Inc employees"
beneficiaries[]
max_accepted_payout1,000,000.000 SBD
percent_steem_dollars10,000
author_curate_reward""
vote details (21)