@@ -139,37 +139,36 @@ NSCopying with a simple call to `foo.copy()` instead of calling
139
139
140
140
## Implementation Experience
141
141
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
146
146
` utils/omit-needless-words.py ` ) and to Swift code itself. The flags
147
147
are:
148
148
149
149
* ` -enable-omit-needless-words ` : this flag enables most of the changes
150
150
to the Clang importer (bullets 1, 2, 4, and 5 in the prior
151
151
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 ] .
153
154
154
155
* ` -enable-infer-default-arguments ` : this flag enables inference of
155
156
default arguments in the Clang importer (bullet 3 in the prior
156
157
section).
157
158
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.
173
172
174
173
## Detailed design
175
174
@@ -507,6 +506,22 @@ if self.managedObjectContext.<b>parent</b> != changedContext { return }
507
506
foregroundColor = .<b >darkGray</b >()
508
507
</pre >
509
508
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
+   ;  ; func dismiss<b >ViewController</b >Animated(flag: Bool, completion: (() -> Void)? = nil)
514
+ }
515
+ </pre >
516
+
517
+ becomes:
518
+
519
+ <pre >
520
+ extension UIViewController {
521
+   ;  ; func dismissAnimated(flag: Bool, completion: (() -> Void)? = nil)
522
+ }
523
+ </pre >
524
+
510
525
##### Why Does Order Matter?
511
526
512
527
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:
553
568
554
569
* ** Option set types** whose type name contain the word "Options" are given a default value of ` [] ` (the empty option set).
555
570
571
+ * ** NSDictionary parameters** with names that involve "options", "attributes", or "info" are given a default value of ` [:] ` .
572
+
556
573
Together, these heuristics allow code like:
557
574
558
575
<pre >
@@ -611,27 +628,13 @@ array.enumerateObjects() { // OK
611
628
}
612
629
</pre >
613
630
614
- #### Prepend "is" to Boolean Properties
631
+ #### Use getter names for Boolean Properties
615
632
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:
617
635
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;
635
638
636
639
will become
637
640
@@ -651,14 +654,24 @@ global symbols defined within that module that can be performed in the
651
654
Clang importer. Note that this removal can create conflicts with the
652
655
standard library. For example, ` NSString ` and ` NSArray ` will become
653
656
` 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 ` .
656
662
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:
658
665
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 >
662
675
663
676
### Conformance of implementers of compare method
664
677
@@ -687,7 +700,7 @@ func compare(otherNumber: NSNumber) -> NSComparisonResult
687
700
688
701
The proposed changes are massively source-breaking for Swift code that
689
702
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 `
691
704
flag described in the [ Implementation
692
705
Experience] ( #implementation-experience ) section can provide the basics
693
706
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.
710
723
[ objc-cocoa-guidelines ] : https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html " Coding Guidelines for Cocoa "
711
724
[ api-design-guidelines ] : https://swift.org/documentation/api-design-guidelines.html " API Design Guidelines "
712
725
[ 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