Swift Basics: Array vs. Set

Поделиться
HTML-код
  • Опубликовано: 4 сен 2024

Комментарии • 50

  • @HaraldAchitz
    @HaraldAchitz Год назад +16

    Just so you know, what you say about performance is only valid for lookup. There are many use-cases where an array is the better solution, even if you scan through the whole thing. Keyword, cache locality . And if you order the array, you will have awesome performance also with search, and the other set operation you showed.
    I would suggest you change the title of the video (but for the youtube algo, that one might be good, also to raise engagement, so maybe leave it for clicks 😁 )

    • @seanallen
      @seanallen  Год назад +5

      I’m experimenting with playing the “RUclips Game”. It feels a little dirty, but my past 2 videos have gotten 3x my typical views in the first 24 hours. It sucks, but the game works. 🤷🏻‍♂️

    • @bonifacy9511
      @bonifacy9511 Год назад +1

      Can you give us a real-life example of using Set instead of a array?

    • @torb-no
      @torb-no Год назад +4

      ​@@seanallen If you're that at least include the more nuanced truth in the video itself. This is bordering on spreading misinformation and is making me feel like I ought to double check stuff I've seen in your videos.
      In this case my experience with C++ arrays made it so I already knew. In fact, I was waiting for you to explain that the truth is more complicated… but I never saw it in the video. Disappointing.
      If you click bait (I understand you gotta play the game), you have *got* to include the nunaced truth in the video somewhere.

    • @TeamPuzel
      @TeamPuzel Год назад

      ​@@torb-no It's even more complicated in Swift though, it's best to avoid mentioning performance at all.
      I'd focus on videos about cool features not everyone might have noticed, or things Swift can express more clearly than other languages. Writing performant code in any language requires deep understanding of memory and how code is compiled rather than memorising which features are "faster" and when.

    • @torb-no
      @torb-no Год назад +1

      @@TeamPuzel My understanding is that if your structs are small enough they have some of the C++ aspects.
      But I suppose Copy-on-Write can make it more complicated too.

  • @jaila17
    @jaila17 Год назад +8

    Hey Sean, nice video!
    You mentioned that Arrays in swift have an O(N) lookup complexity.
    Arrays actually conform to the RandomAccessCollection protocol, which buys us back the O(1) complexity for a lot of the array's functionality.

    • @mivico
      @mivico Год назад +2

      You’re both correct. I believe he was referring to when you don’t know where the item you’re looking for is stored. Then it’s O(N) complexity but if you do know the index that it’s stored in, then it’s O(1) complexity

  • @kdtechniquesofficial6153
    @kdtechniquesofficial6153 Год назад +2

    I think you mistakenly union the same sets instead swiftUIDevs + SwiftDevs.

  • @foilhat
    @foilhat Год назад +6

    And then you convert sets to arrays anyway to store in Core Data.

    • @priceringo1756
      @priceringo1756 Год назад +3

      ...and not just Array but NSArray. I am hoping for more native Swift support from CoreData this WWDC but I am not holding my breath.

  • @kdtechniquesofficial6153
    @kdtechniquesofficial6153 Год назад

    Never Knew about Sets. I've been using Arrays all this time. Thanks, sean. Valuable video, and I learned something new today.

  • @edward.narvaez
    @edward.narvaez Год назад +2

    Thank you Sean

  • @bloq2877
    @bloq2877 Год назад +1

    Great video!

  • @tokero5199
    @tokero5199 Год назад +2

    Actually reading from an Array (if you have the index) is O(1) which is often the case...

    • @seanallen
      @seanallen  Год назад +1

      Fair point, but I disagree that you often have the index. Most of the time I’ve worked with arrays the data is dynamic and I don’t know the index of an item ahead of time.

  • @ruslangaliev5050
    @ruslangaliev5050 Год назад +1

    Thanks a lot for this video! It’s was very useful!

    • @seanallen
      @seanallen  Год назад

      Glad you enjoyed it, Ruslan!

  • @Patrick462
    @Patrick462 Год назад

    I love arrays, back from the old days. But sets are awesome!

  • @MosabbirSadman
    @MosabbirSadman Год назад +1

    Hey Sean! Great content as always!
    Got to know about the practical use of the set operators.
    Excited to use them from now on 😃
    Also wanted to let you know that your fingers might have slipped during demonstrating the union example. 😄
    But that's completely understandable...
    Looking forward to your next video 😃

  • @indomitabletr1834
    @indomitabletr1834 Год назад +1

    Can you make a video about these methods as well ?
    lexicographicallyPrecedes
    withContiguousStorageIfAvailable
    makeIterator
    reserveCapacity
    underestimatedCount
    withUnsafeBufferPointer
    partition
    Maybe there are some more.

  • @slmille4
    @slmille4 Год назад +2

    Since as Swift devs we're probably doing UI, we should generally be using FetchRequests instead of Arrays or Sets to populate UI. FetchRequests get automatic updates when the database changes and has a sort function built in.

  • @arkemal
    @arkemal Год назад

    I love Sets! Good shout Sean!

  • @arthurdeboer8846
    @arthurdeboer8846 Год назад +2

    What if there are two students with the same name?

  • @ameyajoshi5673
    @ameyajoshi5673 Год назад

    Hey Sean, while I agree with you, I use Sets when I wanna store exclusive values like say an Order Number for a Product that is sold, which is unique.

  • @NikDany
    @NikDany Год назад

    Great video, but what will you say about pagination and order? How can I avoid an array?

  • @vikasgupta6657
    @vikasgupta6657 Год назад

    It's really great and helpful video, and I just give one suggestion, pls add subtitle if possible, because, RUclips CC is not accurate and my English not fluent, so it's really hard for me to understand you Said, I hope you are getting my point. Anyway very helpful video ❤ 😍

  • @abhijeetcherungottil6703
    @abhijeetcherungottil6703 Год назад

    Can you give real life example not using set, say can we use it in tableview or anything similar

  • @DaveJacobseniOS
    @DaveJacobseniOS Год назад +2

    Solid info here! Sets have been a rare encounter in all my development days but they are pretty awesome.

  • @ToddHoff
    @ToddHoff Год назад

    Is the performance difference something you've seen in your apps? Since it's all in memory, I wouldn't think it mattered that much.

  • @bosch5053
    @bosch5053 Год назад +1

    nice video!

  • @JustinWellsDev
    @JustinWellsDev Год назад +1

    Sean: When you need a collection of something in Swift, you instinctively reach for an array. Don't you?
    Me: 👀 .............nooooooooooooo?

  • @vongodric
    @vongodric Год назад

    Oh... the date?

  • @victorriurean
    @victorriurean Год назад

    nice

  • @xpopcornx1747
    @xpopcornx1747 Год назад

    Set don't work well with SwiftUI though.

  • @kadeus
    @kadeus Год назад +1

    I’m not agree Array is not Set and Set could not be Array

  • @ItzTalha
    @ItzTalha Год назад +1

    Hi sir.
    I need pubg mobile redeem code of testflight please help please 🙏

  • @ivanramirez1465
    @ivanramirez1465 Год назад

    Guilty 😳

  • @spelledfunny
    @spelledfunny Год назад

    This name example is a terrible sample case. For example, if you're using Sets to determine permissions, anyone in the company with the same first name will all have the same access to whatever the software is in control of, which could be very undesirable if there was a Sean who was a Jr. Dev and another Sean who was at the C-level.

  • @user-zy3xt7mv9m
    @user-zy3xt7mv9m Год назад

    This is not an appropriate title for this video, sorry. Valid uses of `Array` outweigh those of `Set` in a typical codebase by several orders of magnitude. The clickbait title isn’t worth the misinformation.

  • @QwertyNPC
    @QwertyNPC Год назад

    No...I can't take this. Stop this, eat that, 10 fucking ways of doing a "10 fucking ways to do something". You won't miss me, I gotta bail.

  • @me.rathore
    @me.rathore Год назад +1

    Click bait. 👎

    • @seanallen
      @seanallen  Год назад

      Fair. Title and thumbnail change coming soon.

    • @me.rathore
      @me.rathore Год назад +1

      @@seanallen appreciate that. I rarely put comments on RUclips, but when i read the title and thought there must be some performance issues related to Arrays. But it’s mostly related to using correct data structure.