Skip to content

Commit 65ae689

Browse files
committed
Merge pull request #2093 from cwillmor/foundation-api-notes
Add Foundation API Notes for Swift 3 naming
2 parents 1af4f60 + 766ec59 commit 65ae689

24 files changed

+880
-172
lines changed

apinotes/Foundation.apinotes

Lines changed: 713 additions & 4 deletions
Large diffs are not rendered by default.

benchmark/utils/ArgParse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public func parseArgs(_ validOptions: [String]? = nil)
5555
continue
5656
}
5757
// Attempt to split it into two components separated by an equals sign.
58-
let components = arg.componentsSeparated(by: "=")
58+
let components = arg.components(separatedBy: "=")
5959
let optionName = components[0]
6060
if validOptions != nil && !validOptions!.contains(optionName) {
6161
print("Invalid option: \(arg)")

lib/ClangImporter/ImportType.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,9 +2097,10 @@ Type ClangImporter::Implementation::importMethodType(
20972097

20982098
bool allowNSUIntegerAsIntInResult = isFromSystemModule;
20992099
if (allowNSUIntegerAsIntInResult) {
2100-
Identifier name = methodName.getBaseName();
2100+
clang::Selector sel = clangDecl->getSelector();
2101+
StringRef name = sel.getNameForSlot(0);
21012102
if (!name.empty()) {
2102-
allowNSUIntegerAsIntInResult = !nameContainsUnsigned(name.str());
2103+
allowNSUIntegerAsIntInResult = !nameContainsUnsigned(name);
21032104
}
21042105
}
21052106

@@ -2179,13 +2180,14 @@ Type ClangImporter::Implementation::importMethodType(
21792180

21802181
bool allowNSUIntegerAsIntInParam = isFromSystemModule;
21812182
if (allowNSUIntegerAsIntInParam) {
2182-
Identifier name;
2183-
if (nameIndex < argNames.size())
2184-
name = argNames[nameIndex];
2183+
StringRef name;
2184+
clang::Selector sel = clangDecl->getSelector();
2185+
if (nameIndex < sel.getNumArgs())
2186+
name = sel.getNameForSlot(nameIndex);
21852187
if (name.empty() && nameIndex == 0)
2186-
name = methodName.getBaseName();
2188+
name = sel.getNameForSlot(0);
21872189
if (!name.empty())
2188-
allowNSUIntegerAsIntInParam = !nameContainsUnsigned(name.str());
2190+
allowNSUIntegerAsIntInParam = !nameContainsUnsigned(name);
21892191
}
21902192

21912193
Type swiftParamTy;

stdlib/public/SDK/Foundation/Foundation.swift

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,19 @@ extension Int : _ObjectiveCBridgeable {
173173
}
174174

175175
public init(_ number: NSNumber) {
176-
self = number.integerValue
176+
self = number.intValue
177177
}
178178

179179
@_semantics("convertToObjectiveC")
180180
public func _bridgeToObjectiveC() -> NSNumber {
181-
return NSNumber(integer: self)
181+
return NSNumber(value: self)
182182
}
183183

184184
public static func _forceBridgeFromObjectiveC(
185185
_ x: NSNumber,
186186
result: inout Int?
187187
) {
188-
result = x.integerValue
188+
result = x.intValue
189189
}
190190

191191
public static func _conditionallyBridgeFromObjectiveC(
@@ -199,7 +199,7 @@ extension Int : _ObjectiveCBridgeable {
199199
public static func _unconditionallyBridgeFromObjectiveC(
200200
_ source: NSNumber?
201201
) -> Int {
202-
return source!.integerValue
202+
return source!.intValue
203203
}
204204
}
205205

@@ -209,19 +209,19 @@ extension UInt : _ObjectiveCBridgeable {
209209
}
210210

211211
public init(_ number: NSNumber) {
212-
self = number.unsignedIntegerValue
212+
self = number.uintValue
213213
}
214214

215215
@_semantics("convertToObjectiveC")
216216
public func _bridgeToObjectiveC() -> NSNumber {
217-
return NSNumber(unsignedInteger: self)
217+
return NSNumber(value: self)
218218
}
219219

220220
public static func _forceBridgeFromObjectiveC(
221221
_ x: NSNumber,
222222
result: inout UInt?
223223
) {
224-
result = x.unsignedIntegerValue
224+
result = x.uintValue
225225
}
226226

227227
public static func _conditionallyBridgeFromObjectiveC(
@@ -235,7 +235,7 @@ extension UInt : _ObjectiveCBridgeable {
235235
public static func _unconditionallyBridgeFromObjectiveC(
236236
_ source: NSNumber?
237237
) -> UInt {
238-
return source!.unsignedIntegerValue
238+
return source!.uintValue
239239
}
240240
}
241241

@@ -250,7 +250,7 @@ extension Float : _ObjectiveCBridgeable {
250250

251251
@_semantics("convertToObjectiveC")
252252
public func _bridgeToObjectiveC() -> NSNumber {
253-
return NSNumber(float: self)
253+
return NSNumber(value: self)
254254
}
255255

256256
public static func _forceBridgeFromObjectiveC(
@@ -286,7 +286,7 @@ extension Double : _ObjectiveCBridgeable {
286286

287287
@_semantics("convertToObjectiveC")
288288
public func _bridgeToObjectiveC() -> NSNumber {
289-
return NSNumber(double: self)
289+
return NSNumber(value: self)
290290
}
291291

292292
public static func _forceBridgeFromObjectiveC(
@@ -322,7 +322,7 @@ extension Bool: _ObjectiveCBridgeable {
322322

323323
@_semantics("convertToObjectiveC")
324324
public func _bridgeToObjectiveC() -> NSNumber {
325-
return NSNumber(bool: self)
325+
return NSNumber(value: self)
326326
}
327327

328328
public static func _forceBridgeFromObjectiveC(
@@ -392,17 +392,17 @@ extension NSNumber : FloatLiteralConvertible, IntegerLiteralConvertible,
392392
BooleanLiteralConvertible {
393393
/// Create an instance initialized to `value`.
394394
public required convenience init(integerLiteral value: Int) {
395-
self.init(integer: value)
395+
self.init(value: value)
396396
}
397397

398398
/// Create an instance initialized to `value`.
399399
public required convenience init(floatLiteral value: Double) {
400-
self.init(double: value)
400+
self.init(value: value)
401401
}
402402

403403
/// Create an instance initialized to `value`.
404404
public required convenience init(booleanLiteral value: Bool) {
405-
self.init(bool: value)
405+
self.init(value: value)
406406
}
407407
}
408408

@@ -1347,7 +1347,7 @@ extension NSKeyedUnarchiver {
13471347

13481348
extension NSURL : _FileReferenceLiteralConvertible {
13491349
private convenience init(failableFileReferenceLiteral path: String) {
1350-
let fullPath = NSBundle.main().path(forResource: path, ofType: nil)!
1350+
let fullPath = NSBundle.main().pathForResource(path, ofType: nil)!
13511351
self.init(fileURLWithPath: fullPath)
13521352
}
13531353

stdlib/public/SDK/Foundation/NSStringAPI.swift

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@ extension String {
160160
/// Returns a human-readable string giving the name of a given encoding.
161161
@warn_unused_result
162162
public static func localizedName(
163-
ofStringEncoding encoding: NSStringEncoding
163+
of encoding: NSStringEncoding
164164
) -> String {
165-
return NSString.localizedName(ofStringEncoding: encoding)
165+
return NSString.localizedName(of: encoding)
166166
}
167167

168168
// + (instancetype)localizedStringWithFormat:(NSString *)format, ...
@@ -251,8 +251,8 @@ extension String {
251251
/// `String` can be converted to a given encoding without loss of
252252
/// information.
253253
@warn_unused_result
254-
public func canBeConverted(toEncoding encoding: NSStringEncoding) -> Bool {
255-
return _ns.canBeConverted(toEncoding: encoding)
254+
public func canBeConverted(to encoding: NSStringEncoding) -> Bool {
255+
return _ns.canBeConverted(to: encoding)
256256
}
257257

258258
// @property NSString* capitalizedString
@@ -277,8 +277,8 @@ extension String {
277277
/// Returns a capitalized representation of the `String`
278278
/// using the specified locale.
279279
@warn_unused_result
280-
public func capitalizedString(with locale: NSLocale?) -> String {
281-
return _ns.capitalizedString(with: locale) as String
280+
public func capitalized(with locale: NSLocale?) -> String {
281+
return _ns.capitalized(with: locale) as String
282282
}
283283

284284
// - (NSComparisonResult)caseInsensitiveCompare:(NSString *)aString
@@ -399,11 +399,9 @@ extension String {
399399
/// Returns an array containing substrings from the `String`
400400
/// that have been divided by characters in a given set.
401401
@warn_unused_result
402-
public func componentsSeparatedByCharacters(
403-
in separator: NSCharacterSet
404-
) -> [String] {
402+
public func components(separatedBy separator: NSCharacterSet) -> [String] {
405403
// FIXME: two steps due to <rdar://16971181>
406-
let nsa = _ns.componentsSeparatedByCharacters(in: separator) as NSArray
404+
let nsa = _ns.components(separatedBy: separator) as NSArray
407405
// Since this function is effectively a bridge thunk, use the
408406
// bridge thunk semantics for the NSArray conversion
409407
return nsa as! [String]
@@ -414,8 +412,8 @@ extension String {
414412

415413
/// Returns an array containing substrings from the `String`
416414
/// that have been divided by a given separator.
417-
public func componentsSeparated(by separator: String) -> [String] {
418-
let nsa = _ns.componentsSeparated(by: separator) as NSArray
415+
public func components(separatedBy separator: String) -> [String] {
416+
let nsa = _ns.components(separatedBy: separator) as NSArray
419417
// Since this function is effectively a bridge thunk, use the
420418
// bridge thunk semantics for the NSArray conversion
421419
return nsa as! [String]
@@ -426,10 +424,10 @@ extension String {
426424
/// Returns a representation of the `String` as a C string
427425
/// using a given encoding.
428426
@warn_unused_result
429-
public func cString(usingEncoding encoding: NSStringEncoding) -> [CChar]? {
427+
public func cString(using encoding: NSStringEncoding) -> [CChar]? {
430428
return withExtendedLifetime(_ns) {
431429
(s: NSString) -> [CChar]? in
432-
_persistCString(s.cString(usingEncoding: encoding))
430+
_persistCString(s.cString(using: encoding))
433431
}
434432
}
435433

@@ -443,11 +441,11 @@ extension String {
443441
/// the `String` encoded using a given encoding.
444442
@warn_unused_result
445443
public func data(
446-
usingEncoding encoding: NSStringEncoding,
444+
using encoding: NSStringEncoding,
447445
allowLossyConversion: Bool = false
448446
) -> NSData? {
449447
return _ns.data(
450-
usingEncoding: encoding,
448+
using: encoding,
451449
allowLossyConversion: allowLossyConversion)
452450
}
453451

@@ -995,8 +993,8 @@ extension String {
995993
/// Returns the number of bytes required to store the
996994
/// `String` in a given encoding.
997995
@warn_unused_result
998-
public func lengthOfBytes(usingEncoding encoding: NSStringEncoding) -> Int {
999-
return _ns.lengthOfBytes(usingEncoding: encoding)
996+
public func lengthOfBytes(using encoding: NSStringEncoding) -> Int {
997+
return _ns.lengthOfBytes(using: encoding)
1000998
}
1001999

10021000
// - (NSRange)lineRangeForRange:(NSRange)aRange
@@ -1086,8 +1084,8 @@ extension String {
10861084
/// converted to lowercase, taking into account the specified
10871085
/// locale.
10881086
@warn_unused_result
1089-
public func lowercaseString(with locale: NSLocale?) -> String {
1090-
return _ns.lowercaseString(with: locale)
1087+
public func lowercased(with locale: NSLocale?) -> String {
1088+
return _ns.lowercased(with: locale)
10911089
}
10921090

10931091
// - (NSUInteger)maximumLengthOfBytesUsingEncoding:(NSStringEncoding)enc
@@ -1096,8 +1094,8 @@ extension String {
10961094
/// `String` in a given encoding.
10971095
@warn_unused_result
10981096
public
1099-
func maximumLengthOfBytes(usingEncoding encoding: NSStringEncoding) -> Int {
1100-
return _ns.maximumLengthOfBytes(usingEncoding: encoding)
1097+
func maximumLengthOfBytes(using encoding: NSStringEncoding) -> Int {
1098+
return _ns.maximumLengthOfBytes(using: encoding)
11011099
}
11021100

11031101
// - (NSRange)paragraphRangeForRange:(NSRange)aRange
@@ -1338,9 +1336,9 @@ extension String {
13381336
/// the `String` into a legal URL string.
13391337
@available(*, deprecated, message: "Use addingPercentEncoding(withAllowedCharacters:) instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent since each URL component or subcomponent has different rules for what characters are valid.")
13401338
public func addingPercentEscapes(
1341-
usingEncoding encoding: NSStringEncoding
1339+
using encoding: NSStringEncoding
13421340
) -> String? {
1343-
return _ns.addingPercentEscapes(usingEncoding: encoding)
1341+
return _ns.addingPercentEscapes(using: encoding)
13441342
}
13451343

13461344
// - (NSString *)stringByAppendingFormat:(NSString *)format, ...
@@ -1439,11 +1437,11 @@ extension String {
14391437
@warn_unused_result
14401438
public func padding(
14411439
toLength newLength: Int,
1442-
with padString: String,
1440+
withPad padString: String,
14431441
startingAt padIndex: Int
14441442
) -> String {
14451443
return _ns.padding(
1446-
toLength: newLength, with: padString, startingAt: padIndex)
1444+
toLength: newLength, withPad: padString, startingAt: padIndex)
14471445
}
14481446

14491447
// @property NSString* stringByRemovingPercentEncoding;
@@ -1506,9 +1504,9 @@ extension String {
15061504
/// by a given encoding.
15071505
@available(*, deprecated, message: "Use removingPercentEncoding instead, which always uses the recommended UTF-8 encoding.")
15081506
public func replacingPercentEscapes(
1509-
usingEncoding encoding: NSStringEncoding
1507+
using encoding: NSStringEncoding
15101508
) -> String? {
1511-
return _ns.replacingPercentEscapes(usingEncoding: encoding)
1509+
return _ns.replacingPercentEscapes(using: encoding)
15121510
}
15131511

15141512
// @property NSString* stringByResolvingSymlinksInPath;
@@ -1589,8 +1587,8 @@ extension String {
15891587
/// converted to uppercase, taking into account the specified
15901588
/// locale.
15911589
@warn_unused_result
1592-
public func uppercaseString(with locale: NSLocale?) -> String {
1593-
return _ns.uppercaseString(with: locale)
1590+
public func uppercased(with locale: NSLocale?) -> String {
1591+
return _ns.uppercased(with: locale)
15941592
}
15951593

15961594
//===--- Omitted due to redundancy with "utf8" property -----------------===//
@@ -1684,7 +1682,7 @@ extension String {
16841682
// Pre-Swift-3 method names
16851683
extension String {
16861684

1687-
@available(*, unavailable, renamed: "localizedName(ofStringEncoding:)")
1685+
@available(*, unavailable, renamed: "localizedName(of:)")
16881686
public static func localizedNameOfStringEncoding(
16891687
_ encoding: NSStringEncoding
16901688
) -> String {
@@ -1696,7 +1694,7 @@ extension String {
16961694
fatalError("unavailable function can't be called")
16971695
}
16981696

1699-
@available(*, unavailable, renamed: "canBeConverted(toEncoding:)")
1697+
@available(*, unavailable, renamed: "canBeConverted(to:)")
17001698
public func canBeConvertedToEncoding(_ encoding: NSStringEncoding) -> Bool {
17011699
fatalError("unavailable function can't be called")
17021700
}
@@ -1722,7 +1720,7 @@ extension String {
17221720
fatalError("unavailable function can't be called")
17231721
}
17241722

1725-
@available(*, unavailable, renamed: "componentsSeparatedByCharacters(in:)")
1723+
@available(*, unavailable, renamed: "components(separatedBy:)")
17261724
public func componentsSeparatedByCharactersIn(
17271725
_ separator: NSCharacterSet
17281726
) -> [String] {
@@ -1804,7 +1802,7 @@ extension String {
18041802
fatalError("unavailable function can't be called")
18051803
}
18061804

1807-
@available(*, unavailable, renamed: "lengthOfBytes(usingEncoding:)")
1805+
@available(*, unavailable, renamed: "lengthOfBytes(using:)")
18081806
public func lengthOfBytesUsingEncoding(_ encoding: NSStringEncoding) -> Int {
18091807
fatalError("unavailable function can't be called")
18101808
}
@@ -1825,12 +1823,12 @@ extension String {
18251823
fatalError("unavailable function can't be called")
18261824
}
18271825

1828-
@available(*, unavailable, renamed: "lowercaseString(with:)")
1826+
@available(*, unavailable, renamed: "lowercased(with:)")
18291827
public func lowercaseStringWith(_ locale: NSLocale?) -> String {
18301828
fatalError("unavailable function can't be called")
18311829
}
18321830

1833-
@available(*, unavailable, renamed: "maximumLengthOfBytes(usingEncoding:)")
1831+
@available(*, unavailable, renamed: "maximumLengthOfBytes(using:)")
18341832
public
18351833
func maximumLengthOfBytesUsingEncoding(_ encoding: NSStringEncoding) -> Int {
18361834
fatalError("unavailable function can't be called")
@@ -1885,7 +1883,7 @@ extension String {
18851883
fatalError("unavailable function can't be called")
18861884
}
18871885

1888-
@available(*, unavailable, renamed: "addingPercentEscapes(usingEncoding:)")
1886+
@available(*, unavailable, renamed: "addingPercentEscapes(using:)")
18891887
public func addingPercentEscapesUsingEncoding(
18901888
_ encoding: NSStringEncoding
18911889
) -> String? {
@@ -1962,7 +1960,7 @@ extension String {
19621960
fatalError("unavailable function can't be called")
19631961
}
19641962

1965-
@available(*, unavailable, renamed: "uppercaseString(with:)")
1963+
@available(*, unavailable, renamed: "uppercased(with:)")
19661964
public func uppercaseStringWith(_ locale: NSLocale?) -> String {
19671965
fatalError("unavailable function can't be called")
19681966
}

0 commit comments

Comments
 (0)