Skip to content

Commit 737ed65

Browse files
committed
Bring SE-0005 up-to-date with the implementation.
1 parent 9e3b94f commit 737ed65

File tree

1 file changed

+61
-46
lines changed

1 file changed

+61
-46
lines changed

proposals/0005-objective-c-name-translation.md

Lines changed: 61 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -139,37 +139,36 @@ NSCopying with a simple call to `foo.copy()` instead of calling
139139

140140
## Implementation Experience
141141

142-
An experimental, partial implementation of this proposal is available
143-
in the main Swift tree behind a set of experimental compiler
144-
flags. With these flags, one can see the results of applying this
145-
proposal to imported Objective-C APIs (e.g., via the script in
142+
An experimental implementation of this proposal is available in the
143+
main Swift repository. There are a set of compiler flags that one can
144+
use to see the results of applying this proposal to imported
145+
Objective-C APIs (e.g., via the script in
146146
`utils/omit-needless-words.py`) and to Swift code itself. The flags
147147
are:
148148

149149
* `-enable-omit-needless-words`: this flag enables most of the changes
150150
to the Clang importer (bullets 1, 2, 4, and 5 in the prior
151151
section). It is currently suitable only for printing the Swift
152-
interface to Objective-C modules (e.g., via `swift-ide-test`).
152+
interface to Objective-C modules (e.g., via `swift-ide-test`) in the
153+
Swift master branch and [Swift 2.2 branch][swift-2_2-branch], and is enabled on the [Swift 3 API Guidelines branch][swift-3-api-guidelines-branch].
153154

154155
* `-enable-infer-default-arguments`: this flag enables inference of
155156
default arguments in the Clang importer (bullet 3 in the prior
156157
section).
157158

158-
* `-Womit-needless-words`: this flag enables a set of compiler
159-
warnings that helps illustrate what Swift code looks like after
160-
following the rules described in this proposal. The most important
161-
part of each warning is its corresponding Fix-It, which updates the
162-
code according to the rules. Tied together with other compiler flags
163-
(e.g., `-fixit-code`, `-fixit-all`) and a script to collect and apply
164-
Fix-Its (in `utils/apply-fixit-edits.py`), this flag provides a
165-
rudimentary migrator that lets us see how Swift code would look
166-
under the proposed changes, updating both declarations and use
167-
sites. It is currently suitable only for printing the Swift
168-
interface to Objective-C modules (e.g., via `swift-ide-test`).
169-
170-
While the implementation is far from complete, it is enough to see the
171-
effects that the proposal has on Objective-C APIs and code that uses
172-
them.
159+
* `-swift3-migration`: only available on the [Swift 2.2
160+
branch][swift-2_2-branch], this flag performs basic migration from
161+
Swift 2 names to the Swift 3 names via Fix-Its. Tied together with
162+
other compiler flags (e.g., `-fixit-code`, `-fixit-all`) and a
163+
script to collect and apply Fix-Its (in
164+
`utils/apply-fixit-edits.py`), this flag provides a rudimentary
165+
migrator that lets us see how Swift code would look under the
166+
proposed changes, updating both declarations and use sites.
167+
168+
To actually get the "Swift 3 experience" of compiling code using these
169+
names, one can use the [Swift 3 API Guidelines
170+
branch][swift-3-api-guidelines-branch], which enables these features
171+
by default along with the changes to the standard library.
173172

174173
## Detailed design
175174

@@ -507,6 +506,22 @@ if self.managedObjectContext.<b>parent</b> != changedContext { return }
507506
foregroundColor = .<b>darkGray</b>()
508507
</pre>
509508

509+
3. **Prune a match for the enclosing type from the base name of a method so long as the match starts after a verb**. For example,
510+
511+
<pre>
512+
extension UI<b>ViewController</b> {
513+
&nbsp;&nbsp;func dismiss<b>ViewController</b>Animated(flag: Bool, completion: (() -> Void)? = nil)
514+
}
515+
</pre>
516+
517+
becomes:
518+
519+
<pre>
520+
extension UIViewController {
521+
&nbsp;&nbsp;func dismissAnimated(flag: Bool, completion: (() -> Void)? = nil)
522+
}
523+
</pre>
524+
510525
##### Why Does Order Matter?
511526

512527
Some steps below prune matches from the head of the first selector
@@ -553,6 +568,8 @@ arguments are added to parameters in the following cases:
553568

554569
* **Option set types** whose type name contain the word "Options" are given a default value of `[]` (the empty option set).
555570

571+
* **NSDictionary parameters** with names that involve "options", "attributes", or "info" are given a default value of `[:]`.
572+
556573
Together, these heuristics allow code like:
557574

558575
<pre>
@@ -611,27 +628,13 @@ array.enumerateObjects() { // OK
611628
}
612629
</pre>
613630

614-
#### Prepend "is" to Boolean Properties
631+
#### Use getter names for Boolean Properties
615632

616-
**Unless the name of a Boolean property contains**
633+
**For Boolean properties, use the name of the getter as the property
634+
name in Swift*. For example:
617635

618-
* **an auxiliary verb** such as "is", "has", "may", "should", or
619-
"will"
620-
621-
* **or, a word ending in "s"** , indicating either a plural (for which
622-
prepending "is" would be incorrect) or a verb in the continuous
623-
tense (which indicates its Boolean nature, e.g., "translates" in
624-
"`translatesCoordinates`")
625-
626-
**prepend "is" to its name**.
627-
628-
For example:
629-
630-
extension NSBezierPath {
631-
var empty: Bool
632-
}
633-
634-
if path.empty { ... }
636+
@interface NSBezierPath : NSObject
637+
@property (readonly,getter=isEmpty) BOOL empty;
635638

636639
will become
637640

@@ -651,14 +654,24 @@ global symbols defined within that module that can be performed in the
651654
Clang importer. Note that this removal can create conflicts with the
652655
standard library. For example, `NSString` and `NSArray` will become
653656
`String` and `Array`, respectively, and Foundation's versions will
654-
shadow the standard library's versions. We are investigating several
655-
ways to address this problem, including:
657+
shadow the standard library's versions. In cases where the Swift 3
658+
names of standard library entities conflict with prefix-stripped
659+
Foundation entities, we retain the `NS` prefix. These Foundation
660+
entities are: `NSArray`, `NSDictionary`, `NSInteger`, `NSRange`,
661+
`NSSet`, and `NSString`.
656662

657-
* Retain the `NS` prefix on such classes.
663+
When the `NS` prefix is stripped from a non-type, lowercase the
664+
initial word. For example:
658665

659-
* Introduce some notion of submodules into Swift, so that these
660-
classes would exist in a submodule for reference-semantic types
661-
(e.g., one would refer to `Foundation.ReferenceTypes.Array` or similar).
666+
<pre>
667+
var NSDateComponentUndefined: Int { get }
668+
</pre>
669+
670+
will become
671+
672+
<pre>
673+
var dateComponentUndefined: Int { get }
674+
</pre>
662675

663676
### Conformance of implementers of compare method
664677

@@ -687,7 +700,7 @@ func compare(otherNumber: NSNumber) -> NSComparisonResult
687700

688701
The proposed changes are massively source-breaking for Swift code that
689702
makes use of Objective-C frameworks, and will require a migrator to
690-
translate Swift 2 code into Swift 3 code. The `-Womit-needless-words`
703+
translate Swift 2 code into Swift 3 code. The `-swift3-migration`
691704
flag described in the [Implementation
692705
Experience](#implementation-experience) section can provide the basics
693706
for such a migrator. Additionally, the compiler needs to provide good
@@ -710,3 +723,5 @@ to fit to this proposal after review by Philippe Hausler.
710723
[objc-cocoa-guidelines]: https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html "Coding Guidelines for Cocoa"
711724
[api-design-guidelines]: https://swift.org/documentation/api-design-guidelines.html "API Design Guidelines"
712725
[core-libraries]: https://swift.org/core-libraries/ "Swift Core Libraries"
726+
[swift-3-api-guidelines-branch]: https://github.com/apple/swift/tree/swift-3-api-guidelines "Swift 3 API Guidelines branch"
727+
[swift-2_2-branch]: https://github.com/apple/swift/tree/swift-2.2-branch "Swift 2.2 branch"

0 commit comments

Comments
 (0)