-
Notifications
You must be signed in to change notification settings - Fork 277
Fix Swift examples for value and reference types swiftlang issue #1268 #1315
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -42,14 +42,21 @@ Since it is an independent instance, changing the `text` of `friendDoc` does not | |
| struct Document { | ||
| var text: String | ||
| } | ||
| ``` | ||
| Example | ||
| ```swift | ||
| class UseStructDocument { | ||
| var myDoc = Document(text: "Great new article") | ||
|
|
||
| var myDoc = Document(text: "Great new article") | ||
| var friendDoc = myDoc | ||
| init() { | ||
| var friendDoc = myDoc | ||
|
|
||
| friendDoc.text = "Blah blah blah" | ||
| friendDoc.text = "Blah blah blah" | ||
|
|
||
| print(friendDoc.text) // prints "Blah blah blah" | ||
| print(myDoc.text) // prints "Great new article" | ||
| print(friendDoc.text) // prints "Blah blah blah" | ||
| print(myDoc.text) // prints "Great new article" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| When you send your friend a copy of a document, you are in complete control of when *your* copy changes. You never have to worry about your friend making some unexpected change to your copy of the document. | ||
|
|
@@ -73,16 +80,26 @@ Since it is a reference to the same instance, changing the `text` of `friendDoc` | |
|
|
||
| ```swift | ||
| class Document { | ||
| var text: String | ||
| } | ||
| var text: String = "" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the added |
||
|
|
||
| var myDoc = Document(text: "Great new article") | ||
| var friendDoc = myDoc | ||
| init(text: String) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The missing |
||
| self.text = text | ||
| } | ||
| } | ||
| ``` | ||
| Example | ||
| ```swift | ||
| class UseClassDocument { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As mentioned in my comment on the PR itself, please revert this section back to the original without the |
||
| var myDoc = Document(text: "Great new article") | ||
|
|
||
| friendDoc.text = "Blah blah blah" | ||
| init() { | ||
| let friendDoc = myDoc | ||
| friendDoc.text = "Blah blah blah" | ||
|
|
||
| print(friendDoc.text) // prints "Blah blah blah" | ||
| print(myDoc.text) // prints "Blah blah blah" | ||
| print(friendDoc.text) // prints "Blah blah blah" | ||
| print(myDoc.text) // prints "Blah blah blah" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| When you send your friend a link to a shared document, your friend can make changes to the document without you knowing about it. You might be relying on your document staying the same. | ||
|
|
||
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.
As mentioned in my comment on the PR itself, please revert this section back to the original without the
UseStructDocumenttype.