mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
This is accomplished by recognizing this specific situation and replacing the 'objc' attribute with a hidden '_objcRuntimeName' attribute. This /only/ applies to classes that are themselves non-generic (including any enclosing generic context) but that have generic ancestry, and thus cannot be exposed directly to Objective-C. This commit also eliminates '@NSKeyedArchiverClassName'. It was decided that the distinction between '@NSKeyedArchiverClassName' and '@objc' was too subtle to be worth explaining to developers, and that any case where you'd use '@NSKeyedArchiverClassName' was already a place where the ObjC name wasn't visible at compile time. This commit does not update diagnostics to reflect this change; we're going to change them anyway. rdar://problem/32414557
98 lines
3.4 KiB
Swift
98 lines
3.4 KiB
Swift
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
@_exported import Foundation // Clang module
|
|
import CoreFoundation
|
|
import CoreGraphics
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// NSObject
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// These conformances should be located in the `ObjectiveC` module, but they can't
|
|
// be placed there because string bridging is not available there.
|
|
extension NSObject : CustomStringConvertible {}
|
|
extension NSObject : CustomDebugStringConvertible {}
|
|
|
|
public let NSNotFound: Int = .max
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// NSLocalizedString
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// Returns a localized string, using the main bundle if one is not specified.
|
|
public
|
|
func NSLocalizedString(_ key: String,
|
|
tableName: String? = nil,
|
|
bundle: Bundle = Bundle.main,
|
|
value: String = "",
|
|
comment: String) -> String {
|
|
return bundle.localizedString(forKey: key, value:value, table:tableName)
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// NSLog
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
public func NSLog(_ format: String, _ args: CVarArg...) {
|
|
withVaList(args) { NSLogv(format, $0) }
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// AnyHashable
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
extension AnyHashable : _ObjectiveCBridgeable {
|
|
public func _bridgeToObjectiveC() -> NSObject {
|
|
// This is unprincipled, but pretty much any object we'll encounter in
|
|
// Swift is NSObject-conforming enough to have -hash and -isEqual:.
|
|
return unsafeBitCast(base as AnyObject, to: NSObject.self)
|
|
}
|
|
|
|
public static func _forceBridgeFromObjectiveC(
|
|
_ x: NSObject,
|
|
result: inout AnyHashable?
|
|
) {
|
|
result = AnyHashable(x)
|
|
}
|
|
|
|
public static func _conditionallyBridgeFromObjectiveC(
|
|
_ x: NSObject,
|
|
result: inout AnyHashable?
|
|
) -> Bool {
|
|
self._forceBridgeFromObjectiveC(x, result: &result)
|
|
return result != nil
|
|
}
|
|
|
|
public static func _unconditionallyBridgeFromObjectiveC(
|
|
_ source: NSObject?
|
|
) -> AnyHashable {
|
|
// `nil` has historically been used as a stand-in for an empty
|
|
// string; map it to an empty string.
|
|
if _slowPath(source == nil) { return AnyHashable(String()) }
|
|
return AnyHashable(source!)
|
|
}
|
|
}
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
// CVarArg for bridged types
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
extension CVarArg where Self: _ObjectiveCBridgeable {
|
|
/// Default implementation for bridgeable types.
|
|
public var _cVarArgEncoding: [Int] {
|
|
let object = self._bridgeToObjectiveC()
|
|
_autorelease(object)
|
|
return _encodeBitsAsWords(object)
|
|
}
|
|
}
|