dart-lang / native

Dart packages related to FFI and native assets bundling.
BSD 3-Clause "New" or "Revised" License
155 stars 43 forks source link

Support `Iterable` on `NSArray` #1474

Open stuartmorgan opened 2 months ago

stuartmorgan commented 2 months ago

This is related to https://github.com/dart-lang/native/issues/1444, but broader in scope.

I wanted to convert some code that was using method channels and did a map(_helperFunctionToConvertElements), and the corresponding code with FFI was a very old-school C-ish style loop-indexes-from-0-to-length-minus-one to manually both convert each element of the array, but also convert the NSArray to a List. If NSArray supported Iterable, then it would have been simple and idiomatic to do the conversion to FFI.

stuartmorgan commented 2 months ago

(After filing this I realized that since I explicitly wanted a List in my use case I could make a helper utility that would convert the NSArray to a generic List and then do the rest of the conversions with Dart-idiomatic map operations, but having that built in to objective_c, especially for cases where someone just needs an Iterable and not a List, would be still be a good quality-of-life improvement.)