Swift Enum - Basics, Raw Values, Associated Values, CaseIterable & More

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024
  • Check out more information on Devmountain:
    bit.ly/35Tzs9K
    In this video we discuss enums (enumerations) in Swift. I explain what enums are, how to use them as constants, Raw Value, CaseIterable, and Associated Values.
    This tutorial was done using Swift 5.2 and Xcode 11.4.
    Swift Documentation about Enums:
    docs.swift.org...
    If you like my teaching style, I've released my first iOS dev course which is all about the take-home project job interview for iOS developers.
    Course Info - seanallen.teac...
    Link to my book - How I Became an iOS Developer:
    gumroad.com/l/...
    Hired.com:
    hired.com/x/1n01g
    Check out my podcast, iOS Dev Discussions:
    itunes.apple.c...
    Book and learning recommendations that help out the channel if you decide to purchase (Affiliate Links):
    Ray Wenderlich Books:
    store.raywende...
    Ray Wenderlich Videos:
    store.raywende...
    Mark Moeykens SwiftUI Views & Animations Mastery:
    www.bigmountai...
    Donny Wals - Combine Framework:
    gumroad.com/a/...
    Paul Hudson's Hacking With Swift:
    gumroad.com/a/...
    Learn Advanced Swift Here:
    gumroad.com/a/...
    Links to my iOS Dev Setup & iOS Dev Book Recommendations
    www.amazon.com...
    Personal Links:
    Twitter:
    / seanallen_dev
    Instagram:
    @seanallen_dev
    #swift #softwaredeveloper #iosdeveloper

ความคิดเห็น • 124

  • @seanallen
    @seanallen  4 ปีที่แล้ว +3

    Watch Next - iOS Dev Launchpad - Beginner Swift Overview - th-cam.com/video/poQZDVKOZOE/w-d-xo.html

  • @david_lev
    @david_lev ปีที่แล้ว +3

    ~ "We'll get there someday" 15:23
    I think you got there in a big way.. Thanks for the great videos!

    • @seanallen
      @seanallen  ปีที่แล้ว +1

      We did. It took a while but we got there. Glad you enjoy the content!

  • @F.Razor718
    @F.Razor718 2 ปีที่แล้ว +3

    I’m a complete beginner and your teaching style is so easy to follow. Thanks for sharing!!!

  • @mathiasriissorensen6994
    @mathiasriissorensen6994 4 ปีที่แล้ว +2

    Whenever I find myself stuck I turn to Sean Allen's videos first. Thanks again!

  • @ghargest66
    @ghargest66 4 ปีที่แล้ว +4

    Thanks for your service to the Swift community Sean. Another home run!

    • @seanallen
      @seanallen  4 ปีที่แล้ว +1

      Thanks for the kind words, Greg 😀

  • @leonidstechlearning2451
    @leonidstechlearning2451 4 ปีที่แล้ว +7

    I didn't know about the underscores to format numbers. Great! :3

    • @seanallen
      @seanallen  4 ปีที่แล้ว +4

      I like throwing in little tips like that in my videos.

  • @naforever1
    @naforever1 3 ปีที่แล้ว +1

    that moment when you wrote "100000" for TH-cam subscribers number and said "we'll get there someday", I stoped the video to subscribe! lol .. great content and teaching style. learned a lot, thank you.. all the best

    • @seanallen
      @seanallen  3 ปีที่แล้ว

      Haha, thanks for the support, Ali. I appreciate it!

  • @bdaralan
    @bdaralan 4 ปีที่แล้ว +5

    Love enum especially when Swift allows associated value to have parameter name. For enum rawValue, I normally use it for database or cache value where the storage can only store primitive type and later I can recreate the enum using the rawValue.

  • @Wheelhouse406
    @Wheelhouse406 2 ปีที่แล้ว +1

    "Lets say 100,000 followers, we'll get there some day." He got there... I appreciate this guy helping me!!

    • @seanallen
      @seanallen  2 ปีที่แล้ว

      Happy to help, Jimmy! And yup, we got there eventually 😀

  • @sarahstice4095
    @sarahstice4095 ปีที่แล้ว

    "100,000 subscribers... we'll get there some day." Sitting at 127k, love to see it. Love your videos, thank you.

  • @keatsp
    @keatsp 3 ปีที่แล้ว

    Well you have one new sub now. Great video. Clear and concise. I am an experienced coder and still enjoyed the video.

  • @tompov227
    @tompov227 ปีที่แล้ว

    I find it super interesting how your keywords are set in Menlo but the rest of your editor is using SF Mono as the font. I know Xcode lets you but I have never seen people use different font faces for different source types

  • @misran449
    @misran449 4 ปีที่แล้ว +19

    i'm just going to pre-like every video from you that i open because at this point i know i will like them

    • @seanallen
      @seanallen  4 ปีที่แล้ว +1

      haha, thanks for the support!

  • @andresuhartanto3385
    @andresuhartanto3385 4 ปีที่แล้ว +9

    Thank you so much for the clear explanation, i understand better about Enum thanks to you!

    • @seanallen
      @seanallen  4 ปีที่แล้ว +2

      Happy to help!

  • @gakkieNL
    @gakkieNL 4 ปีที่แล้ว +1

    Nice video. Very educational and easy to follow! Thanks Sean!

    • @seanallen
      @seanallen  4 ปีที่แล้ว

      My pleasure!

  • @ketanchoyal7024
    @ketanchoyal7024 3 ปีที่แล้ว +1

    Awesome just what I was looking for, Thanks

    • @seanallen
      @seanallen  3 ปีที่แล้ว +1

      Glad I could help!

  • @yuriisameliuk2118
    @yuriisameliuk2118 4 ปีที่แล้ว +1

    Good video . Thanks you Sean.

  • @mr.iguide7508
    @mr.iguide7508 4 ปีที่แล้ว +2

    This video was so needed. Thank you.

  • @Karma_Rinku
    @Karma_Rinku 3 ปีที่แล้ว

    You did not tell about recursive enum the last topic i waiting to see this but.. not there. bcoz i was confused in that . make on that a video

  • @mrmillmill
    @mrmillmill 2 ปีที่แล้ว

    Anyone have any ideas for creating a function that adds cases to an enum?

  • @brandonwinston
    @brandonwinston 4 ปีที่แล้ว +1

    thank you!

    • @seanallen
      @seanallen  4 ปีที่แล้ว

      Happy to help

  • @maheshgvelly
    @maheshgvelly 4 ปีที่แล้ว

    Whats a recursive enum?

  • @nileshjdarji
    @nileshjdarji 4 ปีที่แล้ว +1

    Awesome 👍

  • @Jeff-zc6rr
    @Jeff-zc6rr 4 หลายเดือนก่อน

    geez.. i'm learning swiftui now.. and everytime i watch something there is something new.. why in the world is there the word "on" before platform..

    • @seanallen
      @seanallen  4 หลายเดือนก่อน

      that's called an argument label. It's mean to help the function be more human readable when you call it.

  • @tajfun6955
    @tajfun6955 4 ปีที่แล้ว +10

    I`m working with swift from 2 years and every day i am finding a small piece of knowledge in videos or article on a medium where i surprised how many smart solutions is in Swift :D.

  • @zzhao463
    @zzhao463 3 ปีที่แล้ว +4

    Even better than the Stanford open class. (well for the parts covered. )

  • @vinrbi8080
    @vinrbi8080 2 ปีที่แล้ว +1

    At 15:23 “100,000 subscribers. We’ll get there one day”
    Almost there! 98.3K right now! And just earned a new one from me. Keep up the good work!

  • @adarshraj312
    @adarshraj312 2 ปีที่แล้ว +1

    new to swift. But, i know this guy... pretty Famous for iOS Dev 👏👏

  • @gurvirsingh4332
    @gurvirsingh4332 ปีที่แล้ว +1

    Haha Cheers to you, U have crossed 100000 subscribers 💥 as u mentioned someday you will reach.

  • @NadiyaLevytska
    @NadiyaLevytska 2 ปีที่แล้ว +1

    15:27 you said " we will get to 100k subs some day" and look at you now! great Channel! keep up amazing work

  • @armandmugabo1170
    @armandmugabo1170 ปีที่แล้ว +1

    congratulations, you hit your once a youtube goal of 100k subs.

  • @MattyFnB
    @MattyFnB 4 ปีที่แล้ว +4

    As always great clear and understandable videos, love your work

    • @seanallen
      @seanallen  4 ปีที่แล้ว +1

      Glad you like them!

  • @kuralaybiehler5638
    @kuralaybiehler5638 ปีที่แล้ว +1

    Thank you! Clear and simple explanation of enum!

    • @seanallen
      @seanallen  ปีที่แล้ว

      Glad you liked it!

  • @gjermundification
    @gjermundification 4 ปีที่แล้ว

    Compiler protocols: `cat /opt/local/dev/swift/stdlib/public/core/CompilerProtocols.swift | grep "public protocol" | grep -v _ | sort` github.com/apple/swift/blob/master/stdlib/public/core/CompilerProtocols.swift

  • @KimbrellBrad
    @KimbrellBrad 2 ปีที่แล้ว

    Less than 2 years later and you are at 99,400 subs! Feels like you were around 20K when I started subscribing. Congrats! Oh, and nice tutorial on enums! LOL

  • @JeffCournoyerATC
    @JeffCournoyerATC 3 ปีที่แล้ว +2

    I’ve been considering doing your GitHub followers class, but this video definitely did it for me! I just signed up and am excited to get started! Love your teaching style man!!!

    • @seanallen
      @seanallen  3 ปีที่แล้ว +1

      Thanks for the kind words, Jeff. Hope you enjoy the course!

  • @pritommazumder9897
    @pritommazumder9897 3 ปีที่แล้ว +2

    A pure community man!

  • @johndickson9709
    @johndickson9709 ปีที่แล้ว

    Recent subscriber, your videos are excellent. Thanks for sharing your knowledge.

  • @thomasswatland
    @thomasswatland 4 ปีที่แล้ว +2

    So many times I've used a Struct with static properties to hold on to related constants, and it feels "off" every time. Naming a Struct with a plural just doesn't sit right. I never thought of just doing the same with enums! That just looks and feels so much better. Thanks Sean, keep up the good work!

  • @Faisal50x
    @Faisal50x 4 ปีที่แล้ว +2

    This is the best swift video ever seen. Damn Thanks Sean Allen for making this cool video.

    • @seanallen
      @seanallen  4 ปีที่แล้ว +2

      Glad you liked it!

  • @harungunes3735
    @harungunes3735 3 ปีที่แล้ว +2

    It's a deep dive with a simple explanation. Thank you, Sean!

  • @cometmace
    @cometmace 4 ปีที่แล้ว +1

    1:18 An enum has to have cases
    4:09 SFSymbols - no cases. Just static lets. Please to be explaining?

    • @saj5935
      @saj5935 4 ปีที่แล้ว

      static let also similar to case you should know static keyword mean

  • @melendezjonas6404
    @melendezjonas6404 3 ปีที่แล้ว

    The jittery ash opportunely water because level additionly alert given a hollow dead. bloody, furry furtive cobweb

  • @paramsingh4104
    @paramsingh4104 2 ปีที่แล้ว

    Swift enums are really advanced, can put Typescript to shame.

  • @dugrut1325
    @dugrut1325 2 ปีที่แล้ว

    i left more confused, i need more, how real data is pushed into an enum and then get the results, for example, if you explained 'func set' more then maybe I would of gotten it.

  • @Rahul-jf5kf
    @Rahul-jf5kf 2 ปีที่แล้ว

    suppose I have multiple fields for each enum case like title, description, image URL. and are static for each case now i want list of all titles, list of all descriptions so son and also one method to get url from title image from title . please explain

  • @donathmm3881
    @donathmm3881 4 ปีที่แล้ว +2

    Good video! What is left is the default case!

    • @seanallen
      @seanallen  4 ปีที่แล้ว +1

      Hehe, it's hard to cover every possible thing 😀

  • @rdtba21qw
    @rdtba21qw 4 ปีที่แล้ว +3

    Sean mate, I’m nearly to the end of your course and have loved it. I had literally set aside the subject of your use of the SFSymbol enum for a point to brush up on when I’m done and you’ve just released this - perfect timing and as always super clear and concise - thank you!

    • @seanallen
      @seanallen  4 ปีที่แล้ว

      Glad you enjoyed it, Robin 😀

  • @lolerskates876
    @lolerskates876 4 ปีที่แล้ว

    I have used Enum for Arduino code. It makes it easier even for what color an LED should be

  • @shadieossei4336
    @shadieossei4336 3 ปีที่แล้ว

    You're gonna get to 100,000 subscribers and be eligible for sponsorship

  • @T0m4sfn
    @T0m4sfn 3 ปีที่แล้ว

    Just here to say you are about 13k left to reach 100k subscribers as the last example follows.

  • @amitarya4894
    @amitarya4894 ปีที่แล้ว +1

    Superb 💯, thanks for this

    • @seanallen
      @seanallen  ปีที่แล้ว +1

      My pleasure 😊

  • @VeryBlueBot
    @VeryBlueBot 4 ปีที่แล้ว +2

    oh man this is so clear! thank you! Love these short gems really speeds up the learning process for a new language!
    Small question (which I probably could have just googled, but hey, Im typing already..) -
    Swift don't have 'default' in its switch statement?

    • @seanallen
      @seanallen  4 ปีที่แล้ว

      Yes, that was something I should have covered in the video. There is a default statement you can use as a "catch-all". In the example in the video, I wanted to show all the options to really illustrate the point. But yes, a simple default case will work as well.

    • @VeryBlueBot
      @VeryBlueBot 4 ปีที่แล้ว

      @@seanallen no worries its just a small thing :) just wanted to make sure its like in any other language..

    • @bitsurfer0101
      @bitsurfer0101 3 ปีที่แล้ว

      @@seanallen You answered my question and explained how to use enums at the same time. I don't feel like I have my head in the sand so much anymore.

  • @joshr9723
    @joshr9723 4 ปีที่แล้ว +1

    I love using Enums that have String rawValues because you can take a string and turn it into type SocialPlatform in this example. ie. let twitterCase = SocialPlatform(rawValue: "This is my favorite!"). This is great if you want to store a string value in your database, but then convert it back to an enum type to make it easier to pass around in your code.

  • @withd5943
    @withd5943 ปีที่แล้ว +1

    One of the best tutorials on enum. Always coming back to refresh my knowledge here. 🙏

    • @seanallen
      @seanallen  ปีที่แล้ว

      Glad it's helpful each time!

  • @prachipatel2841
    @prachipatel2841 3 ปีที่แล้ว +1

    Great Example, I understand whole concept of ENUM and how it can be useful. Thank You so much! 😊

    • @seanallen
      @seanallen  3 ปีที่แล้ว +1

      Happy to help, Prachi!

  • @3909630
    @3909630 4 ปีที่แล้ว +1

    I usually insta-like every video from you, BUT YES IVE BEEN WAITING FOR THISSSSSSSSSS

  • @dugrut1325
    @dugrut1325 2 ปีที่แล้ว

    what is 'ItemInfoType' ???

  • @KanyantaMubanga
    @KanyantaMubanga 2 ปีที่แล้ว

    You said:100k subscribers, we'll get there some day.
    97.1k right now. That day's getting closer and closer Sean. Rooting for you!

  • @steknika
    @steknika 2 ปีที่แล้ว

    when you say “you’ll get there” on the 100k, but currently it is a 103k is priceless! keep up the good work!

  • @shynepo6
    @shynepo6 2 ปีที่แล้ว

    Sean: " 100k subs, we'll get there someday" ... Almost there man!! thanks for providing massive value to people on the IOS dev journey!

  • @vickyphan5494
    @vickyphan5494 3 ปีที่แล้ว +1

    Thanks for a great video!! What bootcamp did you go to?

    • @seanallen
      @seanallen  3 ปีที่แล้ว

      Glad you liked it, Vicky! I went to one called Mobile Makers in San Francisco back in 2015. It actually no longer exists.

  • @mrmillmill
    @mrmillmill 2 ปีที่แล้ว

    Incredible video and explanation of enum's Sean. It seems like enum's could be used all through out an app. Thank you sir.

  • @mohdrahib1690
    @mohdrahib1690 3 ปีที่แล้ว

    Hi Sean, thanks for explaining Enum
    I have a question
    why an stored property can not be associated with enum ??

  • @lycansre
    @lycansre 4 ปีที่แล้ว +1

    so much depth in your videos I like it you cleared almost everything about enums

    • @seanallen
      @seanallen  4 ปีที่แล้ว

      Happy to hear it was helpful, Meshall 😀

  • @ashokkumarmuthyam2986
    @ashokkumarmuthyam2986 4 ปีที่แล้ว +1

    Thank you sir. Your demonstration is awesome.I am from India.

    • @seanallen
      @seanallen  4 ปีที่แล้ว

      Happy to help!

  • @guruitcompany
    @guruitcompany 4 ปีที่แล้ว +1

    Awesome! Thanks 👍

  • @arslankhalid2919
    @arslankhalid2919 4 ปีที่แล้ว

    Hi, good to watch your video. please make a complete Deep video on computed and stored properties in swift.
    Thanks a lot

  • @prachibile2798
    @prachibile2798 3 ปีที่แล้ว

    I really liked this video so much. As I am a new learner of iOS it was so useful.

  • @Omeir34
    @Omeir34 4 ปีที่แล้ว +1

    Great tutorials Sean!

  • @nuwansameera9519
    @nuwansameera9519 4 ปีที่แล้ว +1

    Thanks you Sean!

  • @eliastabaka
    @eliastabaka ปีที่แล้ว

    Great tutorial!

  • @mellamoraymond
    @mellamoraymond 4 ปีที่แล้ว

    Hi Sean. What's the difference of using enum vs struct when it comes to constant?

  • @JonatanEdOrtiz
    @JonatanEdOrtiz 3 ปีที่แล้ว

    Great video!

  • @CraigSchubert
    @CraigSchubert 4 ปีที่แล้ว +1

    Great content yet again - thanks! :-)

    • @seanallen
      @seanallen  4 ปีที่แล้ว

      Glad you enjoyed it!

  • @maliknrishabh
    @maliknrishabh 4 ปีที่แล้ว

    Another way to use enums could be computed vars

  • @erickramones2167
    @erickramones2167 4 ปีที่แล้ว

    any videos on when to use private or public properties?

    • @seanallen
      @seanallen  4 ปีที่แล้ว +1

      I created a video about access control here: th-cam.com/video/RFGEzkBa834/w-d-xo.html

    • @erickramones2167
      @erickramones2167 4 ปีที่แล้ว

      @@seanallen cool, thanks.

  • @nikandrmarhal
    @nikandrmarhal 4 ปีที่แล้ว

    You also haven’t mentioned the `if case let` syntax. Would be a great topic for another video

    • @seanallen
      @seanallen  4 ปีที่แล้ว

      Yup, it's a difficult balance to make a concise video, but also cover enough of the fundamentals. It's hard to cover every aspect of a topic in one video.

  • @farakhakimov
    @farakhakimov 4 ปีที่แล้ว

    I think we can use default state instead of using all other cases on the last example 🙂

    • @seanallen
      @seanallen  4 ปีที่แล้ว

      You are correct. That would work.

  • @natelehoux7604
    @natelehoux7604 4 ปีที่แล้ว

    Best intro to enums I've found anywhere!

    • @seanallen
      @seanallen  4 ปีที่แล้ว

      Thanks for the kind words, Nate!

  • @RahulPahuja1991
    @RahulPahuja1991 4 ปีที่แล้ว

    Beautifully done thanks

    • @seanallen
      @seanallen  4 ปีที่แล้ว

      Happy to help!

  • @rrakesh05
    @rrakesh05 4 ปีที่แล้ว

    Just awesome tutorial mate...

    • @seanallen
      @seanallen  4 ปีที่แล้ว

      Glad you liked it

  • @MarkizBoneco
    @MarkizBoneco ปีที่แล้ว

    You've achieved 100k subscribers