Opaque Types in Swift Explained (2023) - iOS

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

КОМЕНТАРІ • 27

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

    Follow for more linkedin.com/in/afrazsiddiqui

  • @lindsaymcrory4215
    @lindsaymcrory4215 Рік тому +7

    Nice! I like the clear explanations and focus on a specific topic in digestible time.

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

    I have read somewhere that in future swift versions there will be compiler warning when you are using protocol types (ex. in method params, inits, etc.) you should specify keyword any. This warning is a result of dispatch types and it helps helps the developer understand performance degradation.
    So we can use generics while using protocols.
    Example:
    protocol MyProtocol {}
    1. func doSomething(message: MyProtocol) {}
    2. func doSomething(message: T) where T: MyProtocol {}
    3. func doSomething(message: some MyProtocol) {}
    This looks like the same, but it isn't. 2nd and 3rd do the same thing using static dispatch, unlike 1st, that uses dynamic dispatch.
    So, the question is, if I'm correct, do you know about it and should we use some keyword to all protocol types even without associated types?

  • @attaliabrown6164
    @attaliabrown6164 9 місяців тому

    This helped alot! Thanks!

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

    Great !! thanks for sharing.

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

    Thank you for the simple explanation much appreciated. Was banging head across room cause of it, read many times couldn't understand the practical use

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

    appreciate 🎉

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

    Thank you for the video! The docs say all of the possible return values must have the same type. However I saw a SwiftUI example which returns different types and that gets compiled successfully.
    struct Navigation: View where Content: View {
    @ViewBuilder var content: () -> Content
    var body: some View {
    if #available(iOS 16, *) {
    return NavigationStack(root: content)
    } else {
    return NavigationView(content: content)
    }
    }
    }
    Could you explain why that works or point me out to some resources with a good explanation? It's been a week trying to understand it...

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

      Oh I guess I’ve found where to dig next. It seems to be the ViewBuilder which does this magic trick

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

    Comparing to Rust, seems like "some" is "impl", and "any" is "dyn"

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

    谢谢,这是一个非常有用的视频。

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

    Thanks for this video, can you make a video on the problem with using any rather than some

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

    So the main idea of some is making type erasing easier, isn’t it? But not using diff types in typealias since it will likely brake the execution

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

    nice

  • @Siberian-Vladik
    @Siberian-Vladik Рік тому

    there are saint people. you're definitely one of them