Swift - Convenience Initializers

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

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

  • @jules619h
    @jules619h 4 года назад +10

    best swift channel on youtube
    change my mind
    keep it up Sean

  • @leromt
    @leromt 4 года назад +2

    Great explanation, Sean. I have been watching your videos for over a year now and i have to say, you have REALLY stepped up your game regarding the quality of your instruction, not to say the "old" videos are bad, just that your latest ones are that much better. Well done.

    • @seanallen
      @seanallen  4 года назад +1

      Thanks for the kind words, Tom. I like to think I'm getting better as well. At least I'd hope so after 3+ years of making video tutorials 😀

    • @leromt
      @leromt 4 года назад

      @@seanallen I taught Computer Science here at the United States Military Academy (West Point) for seven years and it seems that your pedagogical approach is aligning with mine. I think you have grown from "informational" videos to "educational" videos, of which the latter is much better for my style of learning and instruction.

  • @TheAhmadReza
    @TheAhmadReza 4 года назад +8

    Your tutorials quality is improving over time!

  • @jscorpio1987
    @jscorpio1987 4 года назад +6

    “We’re not web developers, we’re iOS developers.”
    Ha! I love that! I’m so sick of everybody just assuming developer == web developer.

  • @noamif
    @noamif 4 года назад +3

    Clear, simple , easy to understand. Thanks you , AGAIN!

  • @Денис-ж3ф5р
    @Денис-ж3ф5р 3 года назад +1

    the number of subscribers grows exponentially. I'm with you from 35_000.

    • @seanallen
      @seanallen  3 года назад +1

      Thanks for the long time support!

    • @Денис-ж3ф5р
      @Денис-ж3ф5р 3 года назад

      @@seanallen thanks for keeping enlightening folks.

  • @Omeir34
    @Omeir34 4 года назад +5

    Great tutorial as always Sean!
    Everyone: "String"
    Sean Allen: "Shhhtring"

    • @TheAhmadReza
      @TheAhmadReza 4 года назад +1

      I tried to pronounce it like him while watching it! 😂

    • @seanallen
      @seanallen  4 года назад +4

      I like my strings to be quiet 🤷🏻‍♂️

  • @iamwhat
    @iamwhat 4 года назад +1

    Typical Sean Allen explainer video: Excellent. Will share around.

  • @tariqAlmazyad
    @tariqAlmazyad 4 года назад +1

    yet another simple , clean , and powerful tutorial for a scalable code !
    Thank you

  • @yuriisameliuk2118
    @yuriisameliuk2118 4 года назад

    Thanks Sean. A great example of how to make the code more flexible.

  • @anatoliyca
    @anatoliyca 3 года назад +1

    thanks for the great explanation!

    • @seanallen
      @seanallen  3 года назад

      Glad it was helpful, Anthony.

  • @nileshjdarji
    @nileshjdarji 4 года назад +1

    Awesome explanation. I never understood this. Now I do. Thanks.

  • @andonidasilvaotero9652
    @andonidasilvaotero9652 4 года назад +1

    Great example, Sean

  • @w0mblemania
    @w0mblemania 4 года назад +1

    Another good video. Thanks Sean.
    A couple of suggestions:
    1. It's recommended to use 'lazy var' instead of 'let' when declaring properties in a UIViewController. This allows the system to instantiate the viewController as quickly as possible, delaying the creation of UI elements until the system really needs them. This can become significant when pre-building viewControllers for, say, a series of screens for use with a PageViewController, for on-boarding etc. Also, it allows us to use a closure that references self. e.g.
    lazy var loginButton: SomeButton = {
    let button = SomeButton()
    button.titleLabel?.text = self.conjugateTheVerb("to go")
    return button
    }()
    2. You can use an availability check to prevent unwanted init() methods from being used at all, and preventing them from appearing in code completion:
    @available(*, unavailable)
    required public init?(coder: NSCoder)
    {
    fatalError("init(coder:) has not been implemented")
    }
    3. A small thing... when setting a UIFont property, you don't have to provide the type. e.g.
    myLabel.font = .systemFont(ofSize: 16)
    Cheers, and keep up the great work. You're one of the best Apple dev RUclipsrs around.

    • @seanallen
      @seanallen  4 года назад +2

      Thanks for the feedback and kind words! I have nuanced thoughts on the lazy var stuff, but way too much to type out in a comment 😀. To sum it up, I agree with you when it comes to "heavy" UI situations, but I don't like to use that method for all UI.

  • @mohamedoshiba4935
    @mohamedoshiba4935 4 года назад +1

    That was simple but very helpful, thank you

  • @onecarwood
    @onecarwood 4 года назад +1

    Slick, nicely explained.

  • @joshuashires
    @joshuashires 3 года назад +1

    Hey Sean, thanks for this contribution. I was wondering though. Why can you not just use the first initialiser to do the same thing? init(_ frame: CGRect, title: String). I might of missed why the convenience keyword benefits this strategy.

  • @jaylensmith6308
    @jaylensmith6308 2 года назад

    Super helpful for a mostly SwiftUI person

  • @AlfredoElizondoLife
    @AlfredoElizondoLife 4 года назад +1

    Very “convenient” lol.
    Nice tut as always thanks for the quality , simpleness, and effort on your teaching.

  • @rabihelias7848
    @rabihelias7848 4 года назад +1

    Keep it up man, all the best

  • @3ilz
    @3ilz 4 года назад

    Very easy to understand, thanks so much!

  • @akshaysomkuwar4758
    @akshaysomkuwar4758 4 года назад +1

    Very nicely explained..👌👌🙏

  • @imatricepte94
    @imatricepte94 4 года назад

    Hi Sean thank you for this tutorial. Is there a way to make this work with storyboard ?

  • @PatricioBenavente
    @PatricioBenavente 4 года назад +1

    I use them a lot in CoreData

  • @toastrecon
    @toastrecon 3 года назад

    Is there a way, or would there even be a use case for, multiple convenience initializers? Maybe like initializing a color with RGB or hex? Wondering about namespace issues.

    • @seanallen
      @seanallen  3 года назад +1

      Yes, it's common to have multiple convenience initializers for different use cases.

  • @yuvrajagarkar8942
    @yuvrajagarkar8942 4 года назад

    Great video man , I have a doubt what is required init?(coder:NSCoder){} , and what is that '?' after the function name can functions be optional too ??

  • @nirmankalia6775
    @nirmankalia6775 4 года назад +1

    you are a saviour! 👍✌️

  • @TobiasRuano
    @TobiasRuano 4 года назад

    Sean quick question: what's the difference between the convenience init and creating a custom one?

  • @mrmillmill
    @mrmillmill 3 года назад

    Why use the keyword convenience in a custom init versus not using it in a custom init?

  • @shurale85
    @shurale85 2 года назад

    The same result we could get by passing button Color to the design init setting up default value, couldn’t we?

  • @Hamzaahmed1985
    @Hamzaahmed1985 4 года назад +1

    Thankyou so much for making my life easy as iOS dev #seanIsBest

  • @Ipat639
    @Ipat639 4 года назад

    Can we extend base uikit classes with convinience init?

  • @manojkarkiuiipp
    @manojkarkiuiipp 4 года назад

    Hey Sean great video, In case of storyboard based apps, you can override awakeFromNib and do the basic setup there and for different style buttons you can inject enum case and configure accordingly, this way, for most of the cases, assigning class (SAButton in your case) and button title in the storyboard works fine.

  • @AW-gj4ji
    @AW-gj4ji 4 года назад

    Hi Sean, based on your usage of convenience initializers in the video. Are they primarily used for programmatically created buttons and UI objects?

    • @seanallen
      @seanallen  4 года назад +1

      I used them mostly with my custom objects. Doesn't necessarily have to be UI objects. Can be model objects as well.

    • @AW-gj4ji
      @AW-gj4ji 4 года назад

      @@seanallen Thanks! I was just wondering if I could make use of them since most of my objects are from the storyboard.

  • @TheBooban
    @TheBooban 4 года назад

    5:45 honestly don't think using convenience init was that much better. Just looks more advanced and fancier. And it seems it can't be used on xibs, have to use awakeFromNib only for the outlets.

  • @sameernawaz6078
    @sameernawaz6078 4 года назад

    Can't we just use a setter, instead of creating secondary init like this??

  • @AnkitRathi7
    @AnkitRathi7 4 года назад

    Is it not possible to write new designated init which calls super.init and do the same thing?

    • @seanallen
      @seanallen  4 года назад +1

      You can, but it's not as flexible.

    • @AnkitRathi7
      @AnkitRathi7 4 года назад

      @@seanallen thanks for reply

  • @akkarinphain2371
    @akkarinphain2371 4 года назад

    plz teach me how design MVVM Pattern 100% programming thk

  • @nopassportUA
    @nopassportUA 2 года назад

    how constraints works without { translatesAutoresizingMaskIntoConstraints = false } ?

  • @explorerAshish2020
    @explorerAshish2020 3 года назад

    good work.. saw a few videos and you have 5 haters for sure. ;) :D

    • @seanallen
      @seanallen  3 года назад

      Haha, it's the internet. Can't please everyone...