steamclock / netable

A Swift library for encapsulating network APIs using Codable in a type-oriented way.
MIT License
99 stars 3 forks source link

Support added to utilize array & iteration methods directly on LossyArray #114

Closed amyoulton closed 1 year ago

amyoulton commented 1 year ago

With the current way LossyArray was set up, we were only able to access the array elements within the element var inside of the LossyArray. This meant that if we wanted to use any methods on our Lossy array, you'd need to access .element, like so:

List {
      ForEach(user.loginData.elements, id: \.self) { item in
           Text("Location: \(item.location)")
       }
 }

It was a really straightforward fix, only needing to conform LossyArray to Random Access Collection. Now, we can use LossyArrays the same way we'd use standard arrays throughout our code, after they've been decoded, like so:

 List {
      ForEach(user.loginData, id: \.self) { item in
           Text("Location: \(item.location)")
      }
 }

You can find even more about this in #113!

amyoulton commented 1 year ago

@brendanlensink Woo! Glad to hear it 🥳