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.
post_id | 84,640,977 |
---|---|
author | tarekadam |
permlink | swift-playground-map-and-filter-steemit-inc-employees |
category | hive-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"} |
created | 2020-02-23 06:09:00 |
last_update | 2020-02-23 06:09:00 |
depth | 0 |
children | 0 |
net_rshares | 1,480,329,126,165 |
last_payout | 2020-03-01 06:09:00 |
cashout_time | 1969-12-31 23:59:59 |
total_payout_value | 0.135 SBD |
curator_payout_value | 0.130 SBD |
pending_payout_value | 0.000 SBD |
promoted | 0.000 SBD |
body_length | 1,486 |
author_reputation | 48,977,881,936,844 |
root_title | "Swift Playground - Map and Filter Steemit.Inc employees" |
beneficiaries | [] |
max_accepted_payout | 1,000,000.000 SBD |
percent_steem_dollars | 10,000 |
author_curate_reward | "" |
voter | weight | wgt% | rshares | pct | time |
---|---|---|---|---|---|
nanzo-scoop | 0 | 561,021,560,669 | 10% | ||
mummyimperfect | 0 | 6,933,967,122 | 10% | ||
ak2020 | 0 | 2,744,504,210 | 10% | ||
famunger | 0 | 264,731,642 | 20% | ||
tarekadam | 0 | 46,758,042,827 | 100% | ||
t-bot | 0 | 297,357,053,652 | 10% | ||
mafeeva | 0 | 8,396,630,967 | 10% | ||
kam.ila | 0 | 306,024,603,557 | 100% | ||
stackin | 0 | 59,209,492,412 | 5% | ||
dandesign86 | 0 | 114,846,008,225 | 50% | ||
techken | 0 | 160,790,817 | 1% | ||
espoem | 0 | 11,668,755,879 | 5% | ||
raise-me-up | 0 | 0 | 0.01% | ||
tetsuod | 0 | 550,639,289 | 100% | ||
fitat40 | 0 | 17,952,703,294 | 10% | ||
laissez-faire | 0 | 224,231,340 | 100% | ||
scoopstakes | 0 | 15,899,638,333 | 10% | ||
nanzo-snaps | 0 | 29,289,358,258 | 10% | ||
steemlondon | 0 | 1,044,223,848 | 6% | ||
driklasbue | 0 | -8,905,088 | -10% | ||
axergii | 0 | -8,905,088 | -10% |