Skip to content

Add Foundation API Notes for Swift 3 naming #2093

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

Merged
merged 4 commits into from
Apr 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
717 changes: 713 additions & 4 deletions apinotes/Foundation.apinotes

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion benchmark/utils/ArgParse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public func parseArgs(_ validOptions: [String]? = nil)
continue
}
// Attempt to split it into two components separated by an equals sign.
let components = arg.componentsSeparated(by: "=")
let components = arg.components(separatedBy: "=")
let optionName = components[0]
if validOptions != nil && !validOptions!.contains(optionName) {
print("Invalid option: \(arg)")
Expand Down
16 changes: 9 additions & 7 deletions lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2097,9 +2097,10 @@ Type ClangImporter::Implementation::importMethodType(

bool allowNSUIntegerAsIntInResult = isFromSystemModule;
if (allowNSUIntegerAsIntInResult) {
Identifier name = methodName.getBaseName();
clang::Selector sel = clangDecl->getSelector();
StringRef name = sel.getNameForSlot(0);
if (!name.empty()) {
allowNSUIntegerAsIntInResult = !nameContainsUnsigned(name.str());
allowNSUIntegerAsIntInResult = !nameContainsUnsigned(name);
}
}

Expand Down Expand Up @@ -2179,13 +2180,14 @@ Type ClangImporter::Implementation::importMethodType(

bool allowNSUIntegerAsIntInParam = isFromSystemModule;
if (allowNSUIntegerAsIntInParam) {
Identifier name;
if (nameIndex < argNames.size())
name = argNames[nameIndex];
StringRef name;
clang::Selector sel = clangDecl->getSelector();
if (nameIndex < sel.getNumArgs())
name = sel.getNameForSlot(nameIndex);
if (name.empty() && nameIndex == 0)
name = methodName.getBaseName();
name = sel.getNameForSlot(0);
if (!name.empty())
allowNSUIntegerAsIntInParam = !nameContainsUnsigned(name.str());
allowNSUIntegerAsIntInParam = !nameContainsUnsigned(name);
}

Type swiftParamTy;
Expand Down
30 changes: 15 additions & 15 deletions stdlib/public/SDK/Foundation/Foundation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,19 @@ extension Int : _ObjectiveCBridgeable {
}

public init(_ number: NSNumber) {
self = number.integerValue
self = number.intValue
}

@_semantics("convertToObjectiveC")
public func _bridgeToObjectiveC() -> NSNumber {
return NSNumber(integer: self)
return NSNumber(value: self)
}

public static func _forceBridgeFromObjectiveC(
_ x: NSNumber,
result: inout Int?
) {
result = x.integerValue
result = x.intValue
}

public static func _conditionallyBridgeFromObjectiveC(
Expand All @@ -199,7 +199,7 @@ extension Int : _ObjectiveCBridgeable {
public static func _unconditionallyBridgeFromObjectiveC(
_ source: NSNumber?
) -> Int {
return source!.integerValue
return source!.intValue
}
}

Expand All @@ -209,19 +209,19 @@ extension UInt : _ObjectiveCBridgeable {
}

public init(_ number: NSNumber) {
self = number.unsignedIntegerValue
self = number.uintValue
}

@_semantics("convertToObjectiveC")
public func _bridgeToObjectiveC() -> NSNumber {
return NSNumber(unsignedInteger: self)
return NSNumber(value: self)
}

public static func _forceBridgeFromObjectiveC(
_ x: NSNumber,
result: inout UInt?
) {
result = x.unsignedIntegerValue
result = x.uintValue
}

public static func _conditionallyBridgeFromObjectiveC(
Expand All @@ -235,7 +235,7 @@ extension UInt : _ObjectiveCBridgeable {
public static func _unconditionallyBridgeFromObjectiveC(
_ source: NSNumber?
) -> UInt {
return source!.unsignedIntegerValue
return source!.uintValue
}
}

Expand All @@ -250,7 +250,7 @@ extension Float : _ObjectiveCBridgeable {

@_semantics("convertToObjectiveC")
public func _bridgeToObjectiveC() -> NSNumber {
return NSNumber(float: self)
return NSNumber(value: self)
}

public static func _forceBridgeFromObjectiveC(
Expand Down Expand Up @@ -286,7 +286,7 @@ extension Double : _ObjectiveCBridgeable {

@_semantics("convertToObjectiveC")
public func _bridgeToObjectiveC() -> NSNumber {
return NSNumber(double: self)
return NSNumber(value: self)
}

public static func _forceBridgeFromObjectiveC(
Expand Down Expand Up @@ -322,7 +322,7 @@ extension Bool: _ObjectiveCBridgeable {

@_semantics("convertToObjectiveC")
public func _bridgeToObjectiveC() -> NSNumber {
return NSNumber(bool: self)
return NSNumber(value: self)
}

public static func _forceBridgeFromObjectiveC(
Expand Down Expand Up @@ -392,17 +392,17 @@ extension NSNumber : FloatLiteralConvertible, IntegerLiteralConvertible,
BooleanLiteralConvertible {
/// Create an instance initialized to `value`.
public required convenience init(integerLiteral value: Int) {
self.init(integer: value)
self.init(value: value)
}

/// Create an instance initialized to `value`.
public required convenience init(floatLiteral value: Double) {
self.init(double: value)
self.init(value: value)
}

/// Create an instance initialized to `value`.
public required convenience init(booleanLiteral value: Bool) {
self.init(bool: value)
self.init(value: value)
}
}

Expand Down Expand Up @@ -1347,7 +1347,7 @@ extension NSKeyedUnarchiver {

extension NSURL : _FileReferenceLiteralConvertible {
private convenience init(failableFileReferenceLiteral path: String) {
let fullPath = NSBundle.main().path(forResource: path, ofType: nil)!
let fullPath = NSBundle.main().pathForResource(path, ofType: nil)!
self.init(fileURLWithPath: fullPath)
}

Expand Down
74 changes: 36 additions & 38 deletions stdlib/public/SDK/Foundation/NSStringAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ extension String {
/// Returns a human-readable string giving the name of a given encoding.
@warn_unused_result
public static func localizedName(
ofStringEncoding encoding: NSStringEncoding
of encoding: NSStringEncoding
) -> String {
return NSString.localizedName(ofStringEncoding: encoding)
return NSString.localizedName(of: encoding)
}

// + (instancetype)localizedStringWithFormat:(NSString *)format, ...
Expand Down Expand Up @@ -251,8 +251,8 @@ extension String {
/// `String` can be converted to a given encoding without loss of
/// information.
@warn_unused_result
public func canBeConverted(toEncoding encoding: NSStringEncoding) -> Bool {
return _ns.canBeConverted(toEncoding: encoding)
public func canBeConverted(to encoding: NSStringEncoding) -> Bool {
return _ns.canBeConverted(to: encoding)
}

// @property NSString* capitalizedString
Expand All @@ -277,8 +277,8 @@ extension String {
/// Returns a capitalized representation of the `String`
/// using the specified locale.
@warn_unused_result
public func capitalizedString(with locale: NSLocale?) -> String {
return _ns.capitalizedString(with: locale) as String
public func capitalized(with locale: NSLocale?) -> String {
return _ns.capitalized(with: locale) as String
}

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

/// Returns an array containing substrings from the `String`
/// that have been divided by a given separator.
public func componentsSeparated(by separator: String) -> [String] {
let nsa = _ns.componentsSeparated(by: separator) as NSArray
public func components(separatedBy separator: String) -> [String] {
let nsa = _ns.components(separatedBy: separator) as NSArray
// Since this function is effectively a bridge thunk, use the
// bridge thunk semantics for the NSArray conversion
return nsa as! [String]
Expand All @@ -426,10 +424,10 @@ extension String {
/// Returns a representation of the `String` as a C string
/// using a given encoding.
@warn_unused_result
public func cString(usingEncoding encoding: NSStringEncoding) -> [CChar]? {
public func cString(using encoding: NSStringEncoding) -> [CChar]? {
return withExtendedLifetime(_ns) {
(s: NSString) -> [CChar]? in
_persistCString(s.cString(usingEncoding: encoding))
_persistCString(s.cString(using: encoding))
}
}

Expand All @@ -443,11 +441,11 @@ extension String {
/// the `String` encoded using a given encoding.
@warn_unused_result
public func data(
usingEncoding encoding: NSStringEncoding,
using encoding: NSStringEncoding,
allowLossyConversion: Bool = false
) -> NSData? {
return _ns.data(
usingEncoding: encoding,
using: encoding,
allowLossyConversion: allowLossyConversion)
}

Expand Down Expand Up @@ -995,8 +993,8 @@ extension String {
/// Returns the number of bytes required to store the
/// `String` in a given encoding.
@warn_unused_result
public func lengthOfBytes(usingEncoding encoding: NSStringEncoding) -> Int {
return _ns.lengthOfBytes(usingEncoding: encoding)
public func lengthOfBytes(using encoding: NSStringEncoding) -> Int {
return _ns.lengthOfBytes(using: encoding)
}

// - (NSRange)lineRangeForRange:(NSRange)aRange
Expand Down Expand Up @@ -1086,8 +1084,8 @@ extension String {
/// converted to lowercase, taking into account the specified
/// locale.
@warn_unused_result
public func lowercaseString(with locale: NSLocale?) -> String {
return _ns.lowercaseString(with: locale)
public func lowercased(with locale: NSLocale?) -> String {
return _ns.lowercased(with: locale)
}

// - (NSUInteger)maximumLengthOfBytesUsingEncoding:(NSStringEncoding)enc
Expand All @@ -1096,8 +1094,8 @@ extension String {
/// `String` in a given encoding.
@warn_unused_result
public
func maximumLengthOfBytes(usingEncoding encoding: NSStringEncoding) -> Int {
return _ns.maximumLengthOfBytes(usingEncoding: encoding)
func maximumLengthOfBytes(using encoding: NSStringEncoding) -> Int {
return _ns.maximumLengthOfBytes(using: encoding)
}

// - (NSRange)paragraphRangeForRange:(NSRange)aRange
Expand Down Expand Up @@ -1338,9 +1336,9 @@ extension String {
/// the `String` into a legal URL string.
@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.")
public func addingPercentEscapes(
usingEncoding encoding: NSStringEncoding
using encoding: NSStringEncoding
) -> String? {
return _ns.addingPercentEscapes(usingEncoding: encoding)
return _ns.addingPercentEscapes(using: encoding)
}

// - (NSString *)stringByAppendingFormat:(NSString *)format, ...
Expand Down Expand Up @@ -1439,11 +1437,11 @@ extension String {
@warn_unused_result
public func padding(
toLength newLength: Int,
with padString: String,
withPad padString: String,
startingAt padIndex: Int
) -> String {
return _ns.padding(
toLength: newLength, with: padString, startingAt: padIndex)
toLength: newLength, withPad: padString, startingAt: padIndex)
}

// @property NSString* stringByRemovingPercentEncoding;
Expand Down Expand Up @@ -1506,9 +1504,9 @@ extension String {
/// by a given encoding.
@available(*, deprecated, message: "Use removingPercentEncoding instead, which always uses the recommended UTF-8 encoding.")
public func replacingPercentEscapes(
usingEncoding encoding: NSStringEncoding
using encoding: NSStringEncoding
) -> String? {
return _ns.replacingPercentEscapes(usingEncoding: encoding)
return _ns.replacingPercentEscapes(using: encoding)
}

// @property NSString* stringByResolvingSymlinksInPath;
Expand Down Expand Up @@ -1589,8 +1587,8 @@ extension String {
/// converted to uppercase, taking into account the specified
/// locale.
@warn_unused_result
public func uppercaseString(with locale: NSLocale?) -> String {
return _ns.uppercaseString(with: locale)
public func uppercased(with locale: NSLocale?) -> String {
return _ns.uppercased(with: locale)
}

//===--- Omitted due to redundancy with "utf8" property -----------------===//
Expand Down Expand Up @@ -1684,7 +1682,7 @@ extension String {
// Pre-Swift-3 method names
extension String {

@available(*, unavailable, renamed: "localizedName(ofStringEncoding:)")
@available(*, unavailable, renamed: "localizedName(of:)")
public static func localizedNameOfStringEncoding(
_ encoding: NSStringEncoding
) -> String {
Expand All @@ -1696,7 +1694,7 @@ extension String {
fatalError("unavailable function can't be called")
}

@available(*, unavailable, renamed: "canBeConverted(toEncoding:)")
@available(*, unavailable, renamed: "canBeConverted(to:)")
public func canBeConvertedToEncoding(_ encoding: NSStringEncoding) -> Bool {
fatalError("unavailable function can't be called")
}
Expand All @@ -1722,7 +1720,7 @@ extension String {
fatalError("unavailable function can't be called")
}

@available(*, unavailable, renamed: "componentsSeparatedByCharacters(in:)")
@available(*, unavailable, renamed: "components(separatedBy:)")
public func componentsSeparatedByCharactersIn(
_ separator: NSCharacterSet
) -> [String] {
Expand Down Expand Up @@ -1804,7 +1802,7 @@ extension String {
fatalError("unavailable function can't be called")
}

@available(*, unavailable, renamed: "lengthOfBytes(usingEncoding:)")
@available(*, unavailable, renamed: "lengthOfBytes(using:)")
public func lengthOfBytesUsingEncoding(_ encoding: NSStringEncoding) -> Int {
fatalError("unavailable function can't be called")
}
Expand All @@ -1825,12 +1823,12 @@ extension String {
fatalError("unavailable function can't be called")
}

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

@available(*, unavailable, renamed: "maximumLengthOfBytes(usingEncoding:)")
@available(*, unavailable, renamed: "maximumLengthOfBytes(using:)")
public
func maximumLengthOfBytesUsingEncoding(_ encoding: NSStringEncoding) -> Int {
fatalError("unavailable function can't be called")
Expand Down Expand Up @@ -1885,7 +1883,7 @@ extension String {
fatalError("unavailable function can't be called")
}

@available(*, unavailable, renamed: "addingPercentEscapes(usingEncoding:)")
@available(*, unavailable, renamed: "addingPercentEscapes(using:)")
public func addingPercentEscapesUsingEncoding(
_ encoding: NSStringEncoding
) -> String? {
Expand Down Expand Up @@ -1962,7 +1960,7 @@ extension String {
fatalError("unavailable function can't be called")
}

@available(*, unavailable, renamed: "uppercaseString(with:)")
@available(*, unavailable, renamed: "uppercased(with:)")
public func uppercaseStringWith(_ locale: NSLocale?) -> String {
fatalError("unavailable function can't be called")
}
Expand Down
Loading