Swift Access Control Explained

Поділитися
Вставка
  • Опубліковано 5 січ 2025

КОМЕНТАРІ • 66

  • @seanallen
    @seanallen  4 роки тому +3

    Watch Next - iOS Take Home Project - Job Interview Practice - Free Preview - ua-cam.com/video/MSIe2y6Fee8/v-deo.html

  • @christostsangaris4785
    @christostsangaris4785 4 роки тому +1

    One of the reasons I purchased your “iOS Dev Job Interview practice” without even thinking, is your crystal clear way to explain things! Keep it up Sean!

    • @seanallen
      @seanallen  4 роки тому +1

      Thanks for the kind words, Christos. Hope you enjoy the course 😀

  • @jeffbezos5665
    @jeffbezos5665 4 роки тому +2

    I had some doubts after reading the swift documentation, but you just cleared them out for me. Thank you again!

  • @sn3aky_pants593
    @sn3aky_pants593 4 роки тому +1

    private(set) is kinda cool too. Gives you read only access, but is private for setters

  • @jameelshehadeh9011
    @jameelshehadeh9011 3 роки тому

    very important topic i got asked about this topic in my last interview, thank you sean

  • @robinandthedog
    @robinandthedog 5 років тому +1

    Thanks for the attention to this, go this in an interview asked.

  • @JasonMitchellAZ
    @JasonMitchellAZ 5 років тому +15

    Hey look, you hit 50k subs - congrats! 🥳

    • @seanallen
      @seanallen  5 років тому +1

      Thanks Jason!

    • @rebeloper
      @rebeloper 5 років тому +1

      Good thing that Sean has left the subscribers count on "open" so we can follow along. Congrats 🎉

    • @seanallen
      @seanallen  5 років тому +1

      Thanks!

  • @AcselRo
    @AcselRo 5 років тому +6

    Apple, please fix the "private" access control to also work in extensions that are in other files, not only in the same file with the declaration. 🤷‍♂️
    Great video!

    • @seanallen
      @seanallen  5 років тому +2

      That would be cool... I'm pretty sure after the back and forth with Access Control that happened form Swift 2 to 4, they've put this topic to bed.

    • @yixe2253
      @yixe2253 5 років тому

      no way, thats going to lead to your code-base being a complete mess!

    • @AcselRo
      @AcselRo 5 років тому

      Yixe Why?
      It’s pretty common when writting ObjC to move categories into separate files than the parent class.

  • @PatricioBenavente
    @PatricioBenavente 5 років тому +1

    Thanks Sean. I did not understand fileprivate.
    Love your videos, good work
    Greetings from Argentina

    • @seanallen
      @seanallen  5 років тому

      Happy you liked the video!

    • @egesucu9225
      @egesucu9225 5 років тому +3

      File= viewcontroller.swift. You can have many classes under a file like (class view, class Student etc.) fileprivate lets you use a method or a variable inside these classes because they are in the same file(viewcontroller.swift) , but private is private in a class! So you cant call the method that you build inside student class into view class because classes can’t see other classes private methods until you initialize it

  • @RizosKonstantinos
    @RizosKonstantinos 5 років тому +2

    This is the video that i was looking for. Thank you Sean.

    • @seanallen
      @seanallen  5 років тому

      Glad you got value out of it 😀

  • @jasurrajabov
    @jasurrajabov 5 років тому +1

    Thank you Sean for great tutorial about Access Control. As an addition I would also like to know about "final", where and why to use.

    • @seanallen
      @seanallen  5 років тому

      I'm creating a playlist for a lot of the keywords in Swift. "Final" is on my list. You'll see that eventually.

    • @rebeloper
      @rebeloper 5 років тому +1

      Hi Jasur. "final" is not an Access Control Specifier, it's a Declaration Modifier. It’s applied to a class to indicate that the class can’t be subclassed. It’s applied to a property, method, or subscript of a class to indicate that a class member can’t be overridden in any subclass. Source: docs.swift.org/swift-book/ReferenceManual/Declarations.html#ID381 Hope it helps :)

  • @SMIKEex
    @SMIKEex 5 років тому +1

    congrats on 50k subscribers Sean.

  • @georgeelsham
    @georgeelsham 5 років тому +5

    We need a `groupprivate` I think! Makes it private to a folder/group, similar to Java’s default access modifier.

  • @farziinsan6760
    @farziinsan6760 2 роки тому

    Excellent tutorial! very clear explanation, thanks!

  • @mazedar_tv
    @mazedar_tv 3 роки тому +1

    So whats difference between Public and Internal?

    • @seanallen
      @seanallen  3 роки тому +1

      Public is exposed to outside projects. For example if you were to import a 3rd party library or SDK, they would need to mark their functions as public so your project would have access to them. Internal is exposed to everything within that specific project.

  • @TheBlueSquirtle
    @TheBlueSquirtle 4 роки тому

    can u pls do more iOS interview questions? I ran through that playlist and the Swift Keywords playlist and need more of ur content bc this really sticks with ur explanations !! Thanks!!!

  • @princekili0422
    @princekili0422 4 роки тому

    Thanks a lot.
    This video is really helpful and easy to understand. 👍👍👍

  • @KFrench1123
    @KFrench1123 5 років тому +1

    Great video Sean, thanks a bunch! Always drill the basics, right 👍

    • @seanallen
      @seanallen  5 років тому +1

      Thanks Kevin. Glad you liked it!

  • @gakkieNL
    @gakkieNL 5 років тому +1

    Online tutorials should use and teach access control more often. Part of proper coding imho... thanks for the video!

    • @seanallen
      @seanallen  5 років тому

      Glad you liked it, Gakkie!

    • @rebeloper
      @rebeloper 5 років тому +1

      Agreed. For example not many know that in SwiftUI you should always set your @State variables to be private

  • @nareshy8379
    @nareshy8379 3 роки тому

    Hi Allen...
    I am requesting
    Please upload setters and getters in swift
    please do this video Allen

  • @honza_kriz_bass
    @honza_kriz_bass 5 років тому +8

    Cool video, as always! As you said, it covers the basics more than enough.
    One little nitpicky thing: I'm sad you didn't include "private(set)" - although I guess it's not a core part of access control, IMO it's a super useful feature!
    (commenting mostly so that the few people who read comments might hear about it for the first time 😀 don't know if you omitted it on purpose)

    • @seanallen
      @seanallen  5 років тому +3

      Thanks JK Kross! I did omit that kind of stuff on purpose because I wanted to keep the video focused on the core principle of Access Control. I imagine this video will mostly help beginners and Jr. devs. That's the tough thing about creating tutorials. It's tough to not discuss all the tangential topics, but I don't want to make the video lose focus, drag on forever, or be too overwhelming for viewers.

    • @honza_kriz_bass
      @honza_kriz_bass 5 років тому +3

      @@seanallen totally understandable! 😎
      I'm just that kind of person who loves being bombarded by information 😂😂😂
      But I think your reasoning is valid - I watched a few "overwhelming" videos when I was a total noob and it certainly did not help 😂 Only recently I watched some of them again and finally understood 😀

    • @seanallen
      @seanallen  5 років тому +4

      Agreed. It's tough to make a video that will fit thousands of different people's learning style and preference. I do my best to find a middle ground.

  • @andrevdw747
    @andrevdw747 5 років тому +1

    Thanks for clear explanation 👍🏻

  • @EmmaKAlexandra
    @EmmaKAlexandra 4 роки тому

    Really wish Xcode let you set access control in bulk or something. I mostly develop packages & marking relevant variables, methods, and structures public or open can be really clumsy and error prone. There’s also really silly things like struct’s memberwise initializer is specifically marked internal. So I can’t remember a time where I wrote a package, added it to a project and created my own initializer and properly marked it public. Really frustrating!

  • @stoqnstoqnov7071
    @stoqnstoqnov7071 5 років тому +1

    Hi Sean, great video but it would have been awesome if at the end you have mentioned that you can give specific access control for property setters like for example 'private(set) var isOn' . But its fine, anyone can read it in the link you gave :)

    • @seanallen
      @seanallen  5 років тому

      Glad you liked that video, Stoqn. I omit that kind of stuff on purpose because I wanted to keep the video focused on the core principle of Access Control. I imagine this video will mostly help beginners and Jr. devs. That's the tough thing about creating tutorials. It's tough to not discuss all the tangential topics, but I don't want to make the video lose focus, drag on forever, or be too overwhelming for viewers.

    • @stoqnstoqnov7071
      @stoqnstoqnov7071 5 років тому +1

      Sean Allen yes Sean you are absolutely right, i bet there are thousand more details that people can point out, but what is the purpose of getting beginners lost in all that ? And after all the more your videos are targeted to a broader audience the better the growth of your channel will be 🙂 Before a couple of moths i tried the exact opposite - a channel showing a really technical stuff and got no views at all ua-cam.com/video/atpB_MaAGFk/v-deo.html
      So keep up the good work mate, i would say you are doing the best job keeping the ios devs up to date on youtube :)
      Wish you all best,
      Stoyan from Bulgaria

    • @seanallen
      @seanallen  5 років тому +1

      Thanks for the kind words!

  • @erickramones2167
    @erickramones2167 5 років тому

    do you have a tutorial on how to read a file in ios development?

  • @aknurasatenova4419
    @aknurasatenova4419 3 роки тому

    Is this encapsulation?

  • @valentine1925
    @valentine1925 5 років тому +1

    love it! thanks sean!!

  • @aishaoh1209
    @aishaoh1209 5 років тому +3

    Excellent tutorial! very clear explanation, thanks! Also, totally unrelated question but what software do you use to create these videos to essentially have Xcode UI & yourself on the same screen?

    • @seanallen
      @seanallen  5 років тому +2

      Glad you liked it. I'm recording myself with a Canon M3 camera, recording my screen with QuickTime, and recording my audio with a Blue Yet microphone. Then I edit that all together in Final Cut Pro. You can see more about my setup at seanallen.co/store.

  • @thewalkerthapa5435
    @thewalkerthapa5435 5 років тому +1

    Thank you. Can you make one video on subscript?

  • @andreagrumpeenlate5813
    @andreagrumpeenlate5813 5 років тому

    Is there an advantage to using private? Is performance affected by degree of access of your code components?

    • @rebeloper
      @rebeloper 5 років тому

      Not that much of a performance boost, but you certainly will help the compiler out if you use private wherever it's appropriate. For example in SwiftUI you should always set your @State vars private.

  • @makkah_life_
    @makkah_life_ 4 роки тому +1

    Thank you so much

  • @omarhussari7666
    @omarhussari7666 2 роки тому +1

    Thanks Alot!

  • @iangrant4756
    @iangrant4756 4 роки тому

    I really wish they’d put a ‘friend’ accessor in Swift, like C++ has!

  • @teakodo
    @teakodo 5 років тому +1

    YES

  • @mediterrenean
    @mediterrenean 3 роки тому

    it seems that Sean was conflating private and fileprivate for the first 4 minutes

  • @davidcbeaudoin
    @davidcbeaudoin 2 роки тому

    Bit of a nitpick, but early on you keep saying you don't want files outside of the example file to have access to the private property. I think you mean other classes, or even better, outside code.