Skip to content

Fix example snippet in Array.swift #34146

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

valeriyvan
Copy link
Contributor

Fix example snippet in Array.swift

Example snippet has several problems:

  • it uses deprecated function write(to:atomically:)

  • snippet and explanation claim bridging [String?] to NSArray is compile error when it's not - bridging works fine, but write(to:atomically:) function fails. Despite retuned fail and true atomically parameter, function writes elements into file until first NSNull and keeps this file in file system. Probably it's another problem which should be filed. cc: @millenomi

This PR uses write(to:) instead of deprecated write(to:atomically:) in example, adds do catch and changes explanation preceding example. I feel that this explanation should be improved. Help is appreciated.

@millenomi
Copy link
Contributor

Note that this file is talking about bridging as it applies to Darwin's Foundation. If write(to:) has a behavior you don't like, you will need to file behavior change requests not with Swift, but with Apple at https://feedbackassistant.apple.com/.

@valeriyvan
Copy link
Contributor Author

@natecook1000, @amartini51 could you please have a look?

@amartini51
Copy link
Member

The documentation for NSString.write(to:atomically:) suggests using write(to:atomically:encoding:) instead. How did you decide to use write(to:)?

Has the bridging behavior changed also? The new discussion (which has some English usage problems we can fix later) tells a different story with regard to optionals.

/// values are bridged as `NSNull`. Therefore `moreColors` could be bridged
/// to `NSArray` as well. Because `write(to:)` method throws exception if it
/// encounters `NSNull` values, `do catch` should be used to check if write
/// succeeded.
Copy link
Member

Choose a reason for hiding this comment

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

The behavior of write(to:) belongs on that symbol's reference, we don't need to repeat it here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I just keep fix write(to:atomically:) => write(to:) removing everything else added to this doc comment?

@valeriyvan
Copy link
Contributor Author

valeriyvan commented Oct 11, 2020

The documentation for NSString.write(to:atomically:) suggests using write(to:atomically:encoding:) instead. How did you decide to use write(to:)?

It not about NSString.write(to:atomically:) but about NSArray.write(to:atomically:). It's deprecated. Therefore I have decided to use NSArray.write(to:).

@valeriyvan
Copy link
Contributor Author

valeriyvan commented Oct 11, 2020

Has the bridging behavior changed also? The new discussion (which has some English usage problems we can fix later) tells a different story with regard to optionals.

Yes, bringing behaviour have changed. Original snippet claims it should be compile error. But snippets compiles without errors and runs without errors.

Original snippet could not be left untouched because it tells wrong story.

@valeriyvan valeriyvan requested a review from amartini51 October 11, 2020 14:14
@AnthonyLatsis
Copy link
Collaborator

@amartini51 ping

@valeriyvan
Copy link
Contributor Author

Should we proceed with this PR or should I close it?
cc @amartini51

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.

4 participants