Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/content/interop/objective-c-interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,7 @@ To initialize the `AVAudioPlayer`,
use the [`initWithContentsOfURL:error:`][] method:

```dart
final player = AVAudioPlayer.alloc().initWithContentsOfURL(
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);

```

This Dart `AVAudioPlayer` object is a wrapper around an underlying
Expand Down
Loading