Skip to content

Commit 24ff368

Browse files
committed
[Foundation] Swift3 API naming feedback
Addresses the following issues: rdar://problem/25992816 -[NSUserDefaults registerDefaults] is being imported as NSUserDefaults.register(), which is confusing rdar://problem/26291437 UserDefaults has 'setURL(forKey:)' instead of 'set(_:forKey:)' rdar://problem/26375229 FileManager overlay has old naming rdar://problem/26090891 NSBundle methods that are overridden in the apinotes incorrectly handle the first argument pattern rdar://problem/26271340 struct URL initializer for fileURLWithFileSystemRepresentation is incorrectly named' rdar://problem/26443640 XMLDTDNode.Kind conflicts with XMLNode.Kind and should be renamed to XMLDTDNode.DTDKind rdar://problem/26500390 registerUndoWithTarget in overlay not updated for new API names rdar://problem/26653451 NSCoder encodeDataObject is misleading rdar://problem/26653653 NSCoder decodeObjectOfClass is redundant rdar://problem/26653694 NSCoder.decodeTopLevelObjectForKey does not follow naming guidelines rdar://problem/26656299 SocketNativeHandle should be a hoisted type to SocketPort https://bugs.swift.org/browse/SR-1903
1 parent 0db73cb commit 24ff368

File tree

6 files changed

+74
-35
lines changed

6 files changed

+74
-35
lines changed

apinotes/Foundation.apinotes

Lines changed: 48 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,10 @@ Classes:
489489
SwiftName: intValue
490490
- Name: unsignedIntegerValue
491491
SwiftName: uintValue
492+
- Name: NSAttributedString
493+
SwiftName: NSAttributedString
492494
- Name: NSOrderedSet
495+
SwiftName: NSOrderedSet
493496
Methods:
494497
- Selector: 'enumerateObjectsWithOptions:usingBlock:'
495498
SwiftName: enumerateObjects(options:using:)
@@ -595,40 +598,57 @@ Classes:
595598
SwiftName: NSXPCListenerEndpoint
596599
- Name: NSAppleScript
597600
SwiftName: NSAppleScript
601+
- Name: NSBundleResourceRequest
602+
SwiftName: NSBundleResourceRequest
598603
- Name: NSBundle
599604
Methods:
600605
- Selector: 'URLForAuxiliaryExecutable:'
601-
SwiftName: urlForAuxiliaryExecutable(_:)
606+
SwiftName: url(forAuxiliaryExecutable:)
602607
MethodKind: Instance
603608
- Selector: 'pathForAuxiliaryExecutable:'
604-
SwiftName: pathForAuxiliaryExecutable(_:)
609+
SwiftName: path(forAuxiliaryExecutable:)
605610
MethodKind: Instance
606611
- Selector: 'URLForResource:withExtension:subdirectory:inBundleWithURL:'
607-
SwiftName: urlForResource(_:withExtension:subdirectory:inBundleWith:)
612+
SwiftName: url(forResource:withExtension:subdirectory:in:)
613+
MethodKind: Class
614+
- Selector: 'URLsForResourcesWithExtension:subdirectory:inBundleWithURL:'
615+
SwiftName: urls(forResourcesWithExtension:subdirectory:in:)
608616
MethodKind: Class
609617
- Selector: 'URLForResource:withExtension:'
610-
SwiftName: urlForResource(_:withExtension:)
618+
SwiftName: url(forResource:withExtension:)
611619
MethodKind: Instance
612620
- Selector: 'URLForResource:withExtension:subdirectory:'
613-
SwiftName: urlForResource(_:withExtension:subdirectory:)
621+
SwiftName: url(forResource:withExtension:subdirectory:)
622+
MethodKind: Instance
623+
- Selector: 'URLsForResourcesWithExtension:subdirectory:'
624+
SwiftName: urls(forResourcesWithExtension:subdirectory:)
614625
MethodKind: Instance
615-
- Selector: 'URLForResource:withExtension:subdirectory:localization:'
616-
SwiftName: urlForResource(_:withExtension:subdirectory:localization:)
626+
- Selector: 'URLsForResourcesWithExtension:subdirectory:localization:'
627+
SwiftName: urls(forResourcesWithExtension:subdirectory:localization:)
617628
MethodKind: Instance
618629
- Selector: 'pathForResource:ofType:inDirectory:'
619-
SwiftName: pathForResource(_:ofType:inDirectory:)
630+
SwiftName: path(forResource:ofType:inDirectory:)
631+
MethodKind: Class
632+
- Selector: 'pathsForResourcesOfType:inDirectory:'
633+
SwiftName: paths(forResourcesOfType:inDirectory:)
620634
MethodKind: Class
621635
- Selector: 'pathForResource:ofType:'
622-
SwiftName: pathForResource(_:ofType:)
636+
SwiftName: path(forResource:ofType:)
623637
MethodKind: Instance
624638
- Selector: 'pathForResource:ofType:inDirectory:'
625-
SwiftName: pathForResource(_:ofType:inDirectory:)
639+
SwiftName: path(forResource:ofType:inDirectory:)
626640
MethodKind: Instance
627641
- Selector: 'pathForResource:ofType:inDirectory:forLocalization:'
628-
SwiftName: pathForResource(_:ofType:inDirectory:forLocalization:)
642+
SwiftName: path(forResource:ofType:inDirectory:forLocalization:)
643+
MethodKind: Instance
644+
- Selector: 'pathsForResourcesOfType:inDirectory:'
645+
SwiftName: paths(forResourcesOfType:inDirectory:)
646+
MethodKind: Instance
647+
- Selector: 'pathsForResourcesOfType:inDirectory:forLocalization:'
648+
SwiftName: paths(forResourcesOfType:inDirectory:forLocalization:)
629649
MethodKind: Instance
630650
- Selector: 'objectForInfoDictionaryKey:'
631-
SwiftName: objectForInfoDictionaryKey(_:)
651+
SwiftName: object(forInfoDictionaryKey:)
632652
MethodKind: Instance
633653
- Name: NSByteCountFormatter
634654
Methods:
@@ -723,16 +743,19 @@ Classes:
723743
SwiftName: mountedVolumeURLs(includingResourceValuesForKeys:options:)
724744
MethodKind: Instance
725745
- Selector: 'URLsForDirectory:inDomains:'
726-
SwiftName: urlsForDirectory(_:inDomains:)
746+
SwiftName: urls(for:in:)
727747
MethodKind: Instance
728748
- Selector: 'URLForDirectory:inDomain:appropriateForURL:create:error:'
729-
SwiftName: urlForDirectory(_:in:appropriateFor:create:)
749+
SwiftName: url(for:in:appropriateFor:create:)
730750
MethodKind: Instance
731751
- Selector: 'URLForUbiquityContainerIdentifier:'
732-
SwiftName: urlForUbiquityContainerIdentifier(_:)
752+
SwiftName: url(forUbiquityContainerIdentifier:)
733753
MethodKind: Instance
734754
- Selector: 'containerURLForSecurityApplicationGroupIdentifier:'
735-
SwiftName: containerURLForSecurityApplicationGroupIdentifier(_:)
755+
SwiftName: containerURL(forSecurityApplicationGroupIdentifier:)
756+
MethodKind: Instance
757+
- Selector: 'URLForPublishingUbiquitousItemAtURL:expirationDate:error:'
758+
SwiftName: url(forPublishingUbiquitousItemAt:expiration:)
736759
MethodKind: Instance
737760
- Name: NSFileVersion
738761
SwiftName: NSFileVersion
@@ -809,6 +832,9 @@ Classes:
809832
MethodKind: Instance
810833
- Name: NSTextCheckingResult
811834
Methods:
835+
- Selector: 'rangeAtIndex:'
836+
SwiftName: rangeAt(_:)
837+
MethodKind: Instance
812838
- Selector: 'resultByAdjustingRangesWithOffset:'
813839
SwiftName: resultByAdjustingRangesWithOffset(_:)
814840
MethodKind: Instance
@@ -933,6 +959,9 @@ Classes:
933959
- Selector: 'setBool:forKey:'
934960
SwiftName: set(_:forKey:)
935961
MethodKind: Instance
962+
- Selector: 'setURL:forKey:'
963+
SwiftName: set(_:forKey:)
964+
MethodKind: Instance
936965
- Selector: 'addSuiteNamed:'
937966
SwiftName: addSuite(named:)
938967
MethodKind: Instance
@@ -1191,7 +1220,7 @@ Tags:
11911220
- Name: NSXMLDocumentContentKind
11921221
SwiftName: XMLDocument.ContentKind
11931222
- Name: NSXMLDTDNodeKind
1194-
SwiftName: XMLDTDNode.Kind
1223+
SwiftName: XMLDTDNode.DTDKind
11951224
- Name: NSXMLNodeKind
11961225
SwiftName: XMLNode.Kind
11971226
- Name: NSXMLParserError
@@ -1238,8 +1267,6 @@ Tags:
12381267
SwiftName: NSString.EnumerationOptions
12391268
- Name: NSURLBookmarkCreationOptions
12401269
SwiftName: NSURL.BookmarkCreationOptions
1241-
- Name: NSURLBookmarkFileCreationOptions
1242-
SwiftName: NSURL.BookmarkFileCreationOptions
12431270
- Name: NSURLBookmarkResolutionOptions
12441271
SwiftName: NSURL.BookmarkResolutionOptions
12451272
- Name: NSURLHandleStatus
@@ -1335,6 +1362,8 @@ Typedefs:
13351362
SwiftName: DistributedNotificationCenter.CenterType
13361363
- Name: NSURLFileProtectionType
13371364
SwiftName: URLFileProtection
1365+
- Name: NSURLBookmarkFileCreationOptions
1366+
SwiftName: NSURL.BookmarkFileCreationOptions
13381367
Globals:
13391368
- Name: NSAppleScriptErrorMessage
13401369
SwiftName: NSAppleScript.errorMessage

stdlib/public/SDK/Foundation/FileManager.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,22 @@ extension FileManager {
2727
renamed syntax should be:
2828
public func replaceItem(at originalItemURL: URL, withItemAt newItemURL: URL, backupItemName: String? = nil, options : FileManager.ItemReplacementOptions = []) throws -> URL?
2929
*/
30-
@available(OSX 10.6, iOS 4.0, *)
30+
31+
@available(*, deprecated, renamed:"replaceItemAt(_:withItemAt:backupItemName:options:)")
3132
public func replaceItemAtURL(originalItemURL: NSURL, withItemAtURL newItemURL: NSURL, backupItemName: String? = nil, options: FileManager.ItemReplacementOptions = []) throws -> NSURL? {
3233
var error: NSError? = nil
3334
if let result = NS_Swift_NSFileManager_replaceItemAtURL_withItemAtURL_backupItemName_options(self, originalItemURL, newItemURL, backupItemName, options, &error) {
3435
return result
3536
}
3637
throw error!
3738
}
39+
40+
@available(OSX 10.6, iOS 4.0, *)
41+
public func replaceItemAt(_ originalItemURL: URL, withItemAt newItemURL: URL, backupItemName: String? = nil, options: FileManager.ItemReplacementOptions = []) throws -> NSURL? {
42+
var error: NSError? = nil
43+
if let result = NS_Swift_NSFileManager_replaceItemAtURL_withItemAtURL_backupItemName_options(self, originalItemURL as URL, newItemURL as URL, backupItemName, options, &error) {
44+
return result
45+
}
46+
throw error!
47+
}
3848
}

stdlib/public/SDK/Foundation/Foundation.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ extension NSSet : Sequence {
715715
}
716716
}
717717

718-
extension OrderedSet : Sequence {
718+
extension NSOrderedSet : Sequence {
719719
/// Return an *iterator* over the elements of this *sequence*.
720720
///
721721
/// - Complexity: O(1).
@@ -1058,7 +1058,7 @@ extension NSArray {
10581058
}
10591059
}
10601060

1061-
extension OrderedSet {
1061+
extension NSOrderedSet {
10621062
// - (instancetype)initWithObjects:(id)firstObj, ...
10631063
public convenience init(objects elements: AnyObject...) {
10641064
self.init(array: elements)
@@ -1078,7 +1078,7 @@ extension NSSet : ArrayLiteralConvertible {
10781078
}
10791079
}
10801080

1081-
extension OrderedSet : ArrayLiteralConvertible {
1081+
extension NSOrderedSet : ArrayLiteralConvertible {
10821082
public required convenience init(arrayLiteral elements: AnyObject...) {
10831083
self.init(array: elements)
10841084
}

stdlib/public/SDK/Foundation/URL.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ public struct URL : ReferenceConvertible, CustomStringConvertible, Equatable {
560560
}
561561

562562
/// Initializes a newly created URL referencing the local file or directory at the file system representation of the path. File system representation is a null-terminated C string with canonical UTF-8 encoding.
563-
public init(fileURLWithFileSystemRepresentation path: UnsafePointer<Int8>, isDirectory: Bool, relativeToURL baseURL: URL?) {
563+
public init(fileURLWithFileSystemRepresentation path: UnsafePointer<Int8>, isDirectory: Bool, relativeTo baseURL: URL?) {
564564
_url = NSURL(fileURLWithFileSystemRepresentation: path, isDirectory: isDirectory, relativeTo: baseURL)
565565
}
566566

@@ -1023,7 +1023,7 @@ extension URL : CustomPlaygroundQuickLookable {
10231023

10241024
extension URL : _FileReferenceLiteralConvertible {
10251025
public init(fileReferenceLiteralResourceName name: String) {
1026-
self = Bundle.main().urlForResource(name, withExtension: nil)!
1026+
self = Bundle.main().url(forResource: name, withExtension: nil)!
10271027
}
10281028
}
10291029

test/1_stdlib/NSSetAPI.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ NSSetAPI.test("CustomStringConvertible") {
4444
var NSOrderedSetAPI = TestSuite("NSOrderedSetAPI")
4545

4646
NSOrderedSetAPI.test("Sequence") {
47-
let result = OrderedSet()
47+
let result = NSOrderedSet()
4848
expectSequenceType(result)
4949
}
5050

5151
NSOrderedSetAPI.test("initWithObjects") {
52-
let result = OrderedSet(objects: 1, "two")
52+
let result = NSOrderedSet(objects: 1, "two")
5353
expectEqualsUnordered([1, "two"], result, compare: compareAnythingAtAll)
5454
}
5555

5656
NSOrderedSetAPI.test("ArrayLiteralConvertible") {
57-
let result: OrderedSet = [1, "two"]
57+
let result: NSOrderedSet = [1, "two"]
5858
expectEqualsUnordered([1, "two"], result, compare: compareAnythingAtAll)
5959
}
6060

6161
NSOrderedSetAPI.test("CustomStringConvertible") {
62-
let result = String(OrderedSet(objects:"a", "b", "c", "42"))
62+
let result = String(NSOrderedSet(objects:"a", "b", "c", "42"))
6363
let expect = "{(\n a,\n b,\n c,\n 42\n)}"
6464
expectEqual(expect, result)
6565
}
@@ -76,7 +76,7 @@ var NSIndexSetAPI = TestSuite("NSIndexSetAPI")
7676

7777
NSIndexSetAPI.test("Sequence") {
7878
let result = NSIndexSet()
79-
expectSequenceType(result)
79+
let _ = expectSequenceType(result)
8080
let s = NSIndexSet(indexesIn: NSMakeRange(1, 1))
8181
var iter = s.makeIterator()
8282
// FIXME: Compiler doesn't accept these terms.

test/1_stdlib/Reflection_objc.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ switch PlaygroundQuickLook(reflecting: somesubclassofnsstring) {
9393
}
9494

9595
// CHECK-NEXT: got the expected quick look attributed string
96-
let astr = AttributedString(string: "yizzle pizzle")
97-
switch PlaygroundQuickLook(reflecting: astr as AttributedString) {
98-
case .attributedString(let astr2 as AttributedString)
99-
where astr === astr2:
96+
let astr = NSAttributedString(string: "yizzle pizzle")
97+
switch PlaygroundQuickLook(reflecting: astr) {
98+
case .attributedString(let astr2)
99+
where astr == astr2:
100100
print("got the expected quick look attributed string")
101101
case _:
102102
print("got something else")
@@ -242,7 +242,7 @@ class HasNumberQLO : CanaryBase {
242242

243243
class HasAttributedQLO : CanaryBase {
244244
@objc var debugQuickLookObject: AnyObject {
245-
let str = AttributedString(string: "attributed string")
245+
let str = NSAttributedString(string: "attributed string")
246246
objc_setAssociatedObject(str, &CanaryHandle, CanaryBase(),
247247
.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
248248
return str

0 commit comments

Comments
 (0)