Indirect Enums in Swift - iOS Tutorial (2023)

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ก.ย. 2024

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

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

    Thank u.it's very useful tips🙂

  • @Andrew-7324
    @Andrew-7324 ปีที่แล้ว

    Cool, never heard about this feature

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

    under the hood
    behind the scene

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

    would be also nice to see a real example of usage including concrete task preferably with any UI visualising this. otherwise how to define why do I need linked list? anyway thank you for your efforts :)

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

    I may be missing something. How do you go about accessing different nodes? Initially thought could use to set up a state machine but haven’t tumbled how to access hierarchy.

  • @dsjove
    @dsjove 7 หลายเดือนก่อน

    how about this...
    enum LinkedListItem {
    indirect case node(T, LinkedListItem? = nil)
    var value: T {
    switch self {
    case .node(let value, let _):
    return value
    }
    }
    var next: LinkedListItem? {
    switch self {
    case .node(let _, let next):
    return next
    }
    }
    }
    extension LinkedListItem: CustomStringConvertible where T: CustomStringConvertible {
    var description: String {
    var node: LinkedListItem? = self
    var str = ""
    while true {
    str = str + node!.value.description
    node = node!.next
    if (node == nil) {
    break
    }
    str = str + "->"
    }
    return str
    }
    }
    typealias LinkedList = LinkedListItem?
    let list = LinkedList.init(.node(9, .node(1, .node(8))))
    print(list!)

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

    Why does swift keep adding these strange constructs to the language? Sure I guess you could use enum this way, but it's going to make maintaining this code confusing down the road.

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

    Thanks for the tips !
    What would be the point of a linked list with enum instead of struct ? would it be more efficient or it is just another way of achieving it ?

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

      Two differing approaches

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

      Seems more ugly and confusing

    • @dsjove
      @dsjove 7 หลายเดือนก่อน

      struct does not support indirect

    • @salihtopcu
      @salihtopcu 6 หลายเดือนก่อน

      Also, which method is better for compiling performance?

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

    It expands the possibilities of data structures created by the language. It is not much used during daily life, but for me is by far the coolest feature form the language.

  • @devayz9305
    @devayz9305 6 หลายเดือนก่อน

    Great, thanks

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

    nice to know about this, but i still cant see ill be using it anywhere. Maybe path finding? but then again why would i use an enum instead a struct?

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

      Theres always multiple ways to do a single thing. Its preference

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

    Take that, algorithm!

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

    why do I need linkedlist structure with indirect enum over normal traditional linkedlist ?

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

      Just another way to implement it.

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

      @@iOSAcademy thank you. I will consider to implement if i need. Looking fancy 😜

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

      ​@@indomitabletr1834For structures like trees and graph, it helps a lot.

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

    Brilliant! Very cool!

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

    Could you add a function to insert in the list?

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

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

    Thanks
    Speech recognition in SwiftUI?
    Please

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

    Cool, thanks

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

    nice

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

    Does enum change the type to a reference one?

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

      Nope. Still value type

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

      @@iOSAcademy Are you sure about it? It seems we can't calculate memory space for indirect enum during
      compilation cause of recursion. So probably enum changes it type to reference?
      P.S Thanks a lot for your tutorials! You're doing great!

    • @Andrew-7324
      @Andrew-7324 ปีที่แล้ว

      Using enums this way doesn't make sense because of value semantics. Accessing some nodes and changing them will produce copies without modifying linked list by itself.

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

    what does a recursive function to traverse this list look like?