Skip to content

Conversation

@liamappelbe
Copy link
Contributor

@liamappelbe liamappelbe commented Nov 5, 2025

Update Objective-C example code for consistency with this pr: dart-lang/native#2746

FFIgen has a heuristic to detect errors returned as out-params, and convert them to thrown errors. But this heuristic wasn't working correctly for the example. Now that it's fixed, this part of the example is a bit cleaner, and actually handles the error instead of ignoring it.

@liamappelbe liamappelbe requested a review from parlough November 5, 2025 03:38
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @liamappelbe, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates an Objective-C interop example to align with recent bug fixes and improvements in FFIgen's error detection and handling. The change simplifies the example code by removing the need for manual nullptr error parameters, allowing FFIgen to automatically process and throw errors, thereby making the example more consistent and robust.

Highlights

  • FFIgen Error Handling: The Objective-C interop example code has been updated to reflect improved error handling capabilities within FFIgen. This enhancement allows FFIgen to correctly detect and convert errors returned as out-parameters into thrown errors, making the example more robust.
  • Code Simplification: The initWithContentsOfURL method call in the example is now cleaner. The explicit error: nullptr parameter has been removed, as FFIgen now automatically manages error propagation, simplifying the Dart code.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates an Objective-C example to align with a recent bug fix in ffigen, which changes how errors are handled. The change simplifies the code by removing an explicit error: nullptr argument. My review includes a suggestion to improve the example by adding a note about the new error handling mechanism, making it more informative for developers.

fileUrl,
error: nullptr,
);
final player = AVAudioPlayer.alloc().initWithContentsOfURL(fileUrl);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This simplification is a good improvement. However, since initWithContentsOfURL can now throw an exception on failure, it would be beneficial for this example to demonstrate or at least mention error handling. This would align with the PR's goal of showing how the error is 'actually handled'.

A simple way to guide users would be to add a comment indicating the need for a try-catch block in a real-world application.

Suggested change
final player = AVAudioPlayer.alloc().initWithContentsOfURL(fileUrl);
// In a real app, you should wrap this in a try-catch block.
final player = AVAudioPlayer.alloc().initWithContentsOfURL(fileUrl);

@dart-github-bot
Copy link
Collaborator

Visit the preview URL for this PR (updated for commit 34ad8d8):

https://dart-dev--pr6990-objc-example-nit-dfzzjo6p.web.app

@liamappelbe
Copy link
Contributor Author

#6991

@liamappelbe liamappelbe closed this Nov 5, 2025
parlough pushed a commit that referenced this pull request Nov 7, 2025
I tried out the revamped Objective-C interop instructions from
#6942 (thank you for updating
them 🙏 ) and noticed a handful of minor issues that this PR addresses:

* Instruct people to add dependencies to the helpers
`package:objective_c` and `package:ffi`.
* Add a missing import to `package:objective_c` to the sample code to
resolve `NSString`.
* Adjusted some file paths to align with best practices (e.g. generate
the bindings into the `lib` directory).
* Fixed a nullability issue by checking `player == null` and bailing
early.
* ~Fixed an issue with the enumeration in the multithreading section.~
Already fixed in #6995.
* Removed the `ignore_for_file` preamble configuration since FFIgen
auto-generates `// ignore_for_file: type=lint`.

I also changed the second half to use highlights in the sample code just
like it is done in the first half. I find that easier for following
along. Plus, in the end you get to see the complete code.

I've also incorporated #6990
into this PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants