Sort, Filter, and Map data arrays in Swift | Continued Learning #13

  Рет қаралды 20,796

Swiftful Thinking

Swiftful Thinking

3 жыл бұрын

Being able to effectively manipulate data in your application is extremely important. Before displaying content on the screen, you will (almost always) want to organize the data to show specific pieces of content. In order to do this, we will learn how to use 3 super-efficient modifiers that Apple provides us with:
1. Sort - organize data by criteria
2. Filter - create a subset of your data
3. Map - transform data from one type to another
As you can imagine, being able to sort, filter, or map data is used ALL the time in production applications. We will learn how to implement these methods and also learn some fancy ways to shorten the code to look like professional developers ;)
Next video: • How to use Core Data w...
Last video: • What is Hashable proto...
🤙 WELCOME BACK 🤙
WEBSITE: www.swiftful-thinking.com
DISCORD: / discord
GITHUB: github.com/SwiftfulThinking/
SAY THANKS: www.buymeacoffee.com/nicksarno

Пікірлер: 53
@denaktepe
@denaktepe 4 ай бұрын
GOD OF SWIFTUI, NO MORE WORDS NEEDED!
@SwiftfulThinking
@SwiftfulThinking 4 ай бұрын
😂
@offthedeepend762
@offthedeepend762 3 күн бұрын
The video editing goes crazy on this one
@bbulliard
@bbulliard 2 жыл бұрын
Such a world class video. Very well explained and detailed. You are the best! Thank you for such a wonderful video
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Thanks Bob!
@bobbynwm
@bobbynwm Жыл бұрын
Thanks a lot Nick! Excellent video as always!
@stefanlindholm3284
@stefanlindholm3284 2 жыл бұрын
Another great video! Thank you Nick!
@mustafasabahy3092
@mustafasabahy3092 2 жыл бұрын
please do not stop , all love from egypt
@andresraigoza2082
@andresraigoza2082 2 жыл бұрын
Awesome explanation!!! 🥳 As always thank you so much!!!
@dugrut1325
@dugrut1325 2 жыл бұрын
loved it, back in the day, with Digital Basic, I use to do Bubble Sort on massive arrays, if I remember you sorted from top and bottom toward the middle,
@benceylan273
@benceylan273 3 жыл бұрын
Very good video. Not only for sort, map and filter but also MVVM. Thank you very much. Liked and subscribed.
@SwiftfulThinking
@SwiftfulThinking 3 жыл бұрын
Thanks for watching and subscribing Ben! 🥳
@kdtechniquesofficial6153
@kdtechniquesofficial6153 2 жыл бұрын
Thanks for the video nick. ❤️
@Nunny25
@Nunny25 3 жыл бұрын
Useful tutorial, thanks
@soru_cevapla_
@soru_cevapla_ 7 ай бұрын
what a video men. I realize i learn something else
@yellowhero9108
@yellowhero9108 2 жыл бұрын
Thank you for the great video! Liked and subscribed.❤️❤️❤️
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Thank you!! 🥳
@jonothen2212
@jonothen2212 Жыл бұрын
That was good brother Appreciate the vid
@mig12394
@mig12394 3 жыл бұрын
thanks, cool the music during updating
@SwiftfulThinking
@SwiftfulThinking 3 жыл бұрын
I didn't want you all to sit in silence haha. GarageBand to the rescue!
@mystride
@mystride 2 жыл бұрын
Have seen $0 or $1 in lots of Swift code. Understand the outcome but still don't get the background/rational to it. Would love a video just on that topic.
@andrejkling3886
@andrejkling3886 3 жыл бұрын
Thank you...
@mig12394
@mig12394 3 жыл бұрын
Thanks a lot
@dimflash1987
@dimflash1987 2 жыл бұрын
Super!
@kashilinghajare-patil6402
@kashilinghajare-patil6402 Жыл бұрын
great videos
@saweekmusic
@saweekmusic 4 ай бұрын
I have not seen the advanced playlist, but I really hope you'll tell us how to combine those filters through user interface. it's like when user chooses which filters they want to use.
@bobbynwm
@bobbynwm Жыл бұрын
Nick, what if we were having two String variables in the struct ( name and representative for eg ) or more? How would we be able to filter by either name or representative hence filter accepts only one Bool condition ? Is there another way to go about it ? ( working on implementing a list with searchable for a struct model that has multiple string variables, and I want to allow the option to filter by multiple string values not only one ).
@moshikof7778
@moshikof7778 2 жыл бұрын
assuming im using firebase db with an object filed that is null, then best practice is to map it with compact map ?
@itsericbruh5415
@itsericbruh5415 Жыл бұрын
So I’m filtering an array of date from fire base. For some reason I’m getting 180% cpu usage then when I comment out my filter function it’s 0. What am I missing here
@koheitateyama6333
@koheitateyama6333 2 жыл бұрын
Thank you for the amazing video! It was just what I was looking for!!! By the way, is it possible to make a button to increase the Points from the dataArray?
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Anything is possible :)
@vamsi3877
@vamsi3877 3 жыл бұрын
Great video 👏 It would be really if you explain diff b/w flat map and compact map
@SwiftfulThinking
@SwiftfulThinking 3 жыл бұрын
Hey Vamsi! As you saw in the video, CompactMap is used to transform data to a new type and exclude items that can't transform properly. FlatMap is used when you have multiple arrays and you want to map them together. It's much less common, so I didn't cover it in the video.
@degisner
@degisner 2 жыл бұрын
perfect explanation
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Thanks Andrew!
@faikcoskuncakr7418
@faikcoskuncakr7418 2 жыл бұрын
I discovered that I didn't actually know (.map) THANKS!!
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Awesome 🚀🔥
@GabeColors
@GabeColors Жыл бұрын
Do you have a video where the array of names is imported from a separate .txt file or.cover file?
@richardalbury
@richardalbury 7 ай бұрын
Try something like let fileText = try String(contentsOfFile: path, encoding: .utf8) let myStrings = fileText.components(separatedBy: .newlines)
@pasha7324
@pasha7324 Жыл бұрын
14:35 can be reduced even more to: dataArray.sorted { $0.points > $1.points } 17:50 filteredArray = dataArray.filter { $0.isVerified } 22:30 filteredArray = dataArray.map { $0.name }
@Sengardisback
@Sengardisback 2 жыл бұрын
Hey Nick I was wondering how to filter on a data array just to show the highest 3 values. Its Kind of sort and filter at the Same time. Is there a simple solution? Thanks in advance And keep up the good work
@richardalbury
@richardalbury 7 ай бұрын
Sort decreasing on value and then take the top 3 values, something like ForEach(vm.sorted.dropLast(vm.sorted.count - 3))
@bbulliard
@bbulliard 2 жыл бұрын
This is very powerful stuff, well explained. I’m from the microsoft sql world. Here we combine several ‘arrays’ matching by user ID(for example), picking data from both arrays that match the user ID. In this way we can do powerful reporting. Is there a way to do that?
@SwiftfulThinking
@SwiftfulThinking 2 жыл бұрын
Hi Bob, if we use CoreData (basically like a local SQL database) we can use Predicates which sound similar to what you're trying to do. In iOS, many of those more complex queries are often done on the back-end though.
@wandahu8058
@wandahu8058 Жыл бұрын
Nice Music Taste.
@raymundoortiz7269
@raymundoortiz7269 2 жыл бұрын
How to make TextField accepts just numbers with FILTER ? no matter is copy and paste.
@lolrie
@lolrie 11 ай бұрын
18:25 how did you fold it into a single line?
@TheIgnorantTrio
@TheIgnorantTrio 10 ай бұрын
Command-Option-Left Arrow
@gucp
@gucp Жыл бұрын
14:45 Closures
@gabrielrml
@gabrielrml 3 жыл бұрын
Different NUMBER of points
@kdtechniquesofficial6153
@kdtechniquesofficial6153 2 жыл бұрын
lemme guess, your computer table is made out of wood, isn't it? I feel it when i put my headphones on and the vibration sound comes through your mic... Waiting for your confirmation reply. haha😜
@dugrut1325
@dugrut1325 2 жыл бұрын
mappedArray = mappedArray.sorted(by: { $0 < $1 })
How to use Core Data with @FetchRequest in SwiftUI | Continued Learning #14
36:34
Эффект Карбонаро и нестандартная коробка
01:00
История одного вокалиста
Рет қаралды 10 МЛН
IQ Level: 10000
00:10
Younes Zarou
Рет қаралды 11 МЛН
How to Filter, Sort, and Map in Swift | Swift Basics #16
16:26
Swiftful Thinking
Рет қаралды 6 М.
Turns out REST APIs weren't the answer (and that's OK!)
10:38
Dylan Beattie
Рет қаралды 128 М.
How to use @ViewBuilder in SwiftUI | Advanced Learning #9
24:01
Swiftful Thinking
Рет қаралды 25 М.
31 nooby C++ habits you need to ditch
16:18
mCoding
Рет қаралды 756 М.
"any" Keyword and Existential types in Swift
4:59
Swift and Tips
Рет қаралды 9 М.
The moment we stopped understanding AI [AlexNet]
17:38
Welch Labs
Рет қаралды 852 М.
NavigationStack - SwiftUI Programmatic Navigation - iOS 16
20:20
The Logging Everyone Should Be Using in .NET
15:34
Nick Chapsas
Рет қаралды 51 М.
Эффект Карбонаро и нестандартная коробка
01:00
История одного вокалиста
Рет қаралды 10 МЛН