Skip to content
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

toString is a dangerous name for the NSString->String conversion method #1819

Open
stuartmorgan opened this issue Dec 17, 2024 · 0 comments
Open
Labels
lang-objective_c Related to Objective C support package:objective_c

Comments

@stuartmorgan
Copy link

stuartmorgan commented Dec 17, 2024

Spot the bug in the code below:

  @override
  Future<String?> getLibraryPath() async {
    return _getUserDirectory(NSSearchPathDirectory.NSLibraryDirectory).toString();
  }

  @override
  Future<String?> getApplicationDocumentsPath() async {
    return _getUserDirectory(NSSearchPathDirectory.NSDocumentDirectory).toString();
  }

  [...]

  NSString? _getUserDirectory(NSSearchPathDirectory directory) {
    ...
  }

I would strongly prefer a toDartString method to do the conversion so that this code (using toDartString in place of toString) wouldn't compile. The current version seems extremely likely to cause mistakes like the above in actual usage, and they won't be caught until runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang-objective_c Related to Objective C support package:objective_c
Projects
Status: Todo
Development

No branches or pull requests

2 participants