Skip to content

Support Iterable on NSArray #1474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
stuartmorgan-g opened this issue Aug 28, 2024 · 3 comments · Fixed by #2214
Closed

Support Iterable on NSArray #1474

stuartmorgan-g opened this issue Aug 28, 2024 · 3 comments · Fixed by #2214

Comments

@stuartmorgan-g
Copy link

This is related to #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-g
Copy link
Author

(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.)

@liamappelbe
Copy link
Contributor

@stuartmorgan-g What about nullability? Should NSArray implement Iterable<ObjCObjectBase> or Iterable<ObjCObjectBase?>

@stuartmorgan-g
Copy link
Author

stuartmorgan-g commented Apr 17, 2025

The standard Objective-C collections cannot contain nils.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants