-
Notifications
You must be signed in to change notification settings - Fork 744
Update Objective-C example code #6990
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
Conversation
Summary of ChangesHello @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 Highlights
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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); |
|
Visit the preview URL for this PR (updated for commit 34ad8d8): |
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.
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.