How to use Dictionaries in Swift | Swift Basics #14

Поділитися
Вставка
  • Опубліковано 20 гру 2024

КОМЕНТАРІ • 14

  • @warrenscorner
    @warrenscorner Рік тому +3

    Fantastic explanation! I installed an app on my iPad called Unwrap. It’s made by Paul Hudson. Anyone that’s searching UA-cam for SwiftUI has heard of him. Anyway, the app is a great tool for testing your knowledge but not so great at teaching. I bombed the sets and dictionary part! I just didn’t get it. After watching this video it became perfectly clear to me how these things operate. Great lessons Nick!

  • @DamadGamer
    @DamadGamer Місяць тому

    At 16:15 why do you need to have the if statement there? Can't you just say let item = postArray[1] to get the same thing?

    • @ETERNITY2OP
      @ETERNITY2OP Місяць тому

      because if that value does not exist app will crash so with if its the best practice

  • @norsegaud
    @norsegaud Рік тому +2

    Hey man, almost through all of these videos. One thing I noticed is that the likes are dropping each video I go further into the playlist. While that's likely because people are giving up, I found myself forgetting to like a video before moving on. Maybe inject in the middle of the video a reminder to like the video and I believe you'll get more.

  • @AdamTabiev
    @AdamTabiev Рік тому

    Thank you Nick! Now I understand dictionaries a little more 🕺

  • @lolrie
    @lolrie Рік тому +1

    Hey Nick! In your postArray vs. postDict example, how come the dictionary item is an optional that needs to be unwrapped but not the array item? Can't they both potentially be empty?

    • @SwiftfulThinking
      @SwiftfulThinking  Рік тому +3

      That’s what I was trying to explain here… accessing keys in a dictionary will return nil if there is no value.. but accessing indexes in an array will crash if there is no item!

    • @lolrie
      @lolrie Рік тому

      @@SwiftfulThinking Ahhh right, didn't make the connection there. Thank you!

  • @911gogogo
    @911gogogo Рік тому

    fantatic. Goat lectures in swift history

  • @nileshjdarji
    @nileshjdarji 4 місяці тому

    Can we have a dictionary with Key and value both as Integers. I am working on an app that can keep a log of show seasons and different episodes. I am trying to persist number of episodes for a particular season using dictionary. so I am doing something like seasonInfo = [1:4, 2:3, 3:2] where for season 1 there are 4 episodes, season 2 there are 3 episodes and so on. If this is a bad approach what option do you recommend?

    • @SwiftfulThinking
      @SwiftfulThinking  4 місяці тому +1

      You can, but more likely your seasons have an ID from your data model or database. So then you’d want to do [seasonId : count] of [String:Int]. This is the most common approach

  • @DouglasRutledge
    @DouglasRutledge 24 дні тому

    Hello Nick, I've been watching you for years, and hope you can help. There is large data in a single array/Entity : eg. EmployeeEntity [person, country, city, street, number] The data can have multiple people in one house. GroupBy:House[country, city, street, number] How do you match two people that may live in the same house. Example match/fetch all the [John & Susan] that live in the same House[ ]. There may be no matches for this couple but these two names could be found at in one matching House [ ] or in many houses.

  • @yt-1161
    @yt-1161 8 місяців тому

    What is the difference between
    var wordCounts: [String: Int] = [:] and
    var wordCounts: Set = [:] ?

  • @sxmiotb2834
    @sxmiotb2834 Рік тому

    Thanks 😊