mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Update Foundation overlay for id-as-Any.
This commit is contained in:
@@ -75,7 +75,7 @@ internal protocol _SwiftNativeFoundationType : class {
|
||||
init(unmanagedImmutableObject: Unmanaged<ImmutableType>)
|
||||
init(unmanagedMutableObject: Unmanaged<MutableType>)
|
||||
|
||||
func mutableCopy(with zone : NSZone) -> AnyObject
|
||||
func mutableCopy(with zone : NSZone?) -> Any
|
||||
|
||||
var hashValue: Int { get }
|
||||
var description: String { get }
|
||||
@@ -115,7 +115,7 @@ extension _SwiftNativeFoundationType {
|
||||
}
|
||||
}
|
||||
|
||||
func mutableCopy(with zone : NSZone) -> AnyObject {
|
||||
func mutableCopy(with zone : NSZone?) -> Any {
|
||||
return _mapUnmanaged { $0.mutableCopy() }
|
||||
}
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ public struct Calendar : CustomStringConvertible, CustomDebugStringConvertible,
|
||||
///
|
||||
/// - parameter identifier: The kind of calendar to use.
|
||||
public init(identifier: Identifier) {
|
||||
let result = __NSCalendarInit(Calendar._toNSCalendarIdentifier(identifier))!
|
||||
let result = __NSCalendarInit(Calendar._toNSCalendarIdentifier(identifier).rawValue as NSString)!
|
||||
_handle = _MutableHandle(adoptingReference: result)
|
||||
_autoupdating = false
|
||||
}
|
||||
|
||||
@@ -51,12 +51,12 @@ internal final class _SwiftNSCharacterSet : _SwiftNativeNSCharacterSet, _SwiftNa
|
||||
}
|
||||
|
||||
@objc(copyWithZone:)
|
||||
func copy(with zone: NSZone? = nil) -> AnyObject {
|
||||
func copy(with zone: NSZone? = nil) -> Any {
|
||||
return _mapUnmanaged { $0.copy(with: zone) }
|
||||
}
|
||||
|
||||
@objc(mutableCopyWithZone:)
|
||||
func mutableCopy(with zone: NSZone? = nil) -> AnyObject {
|
||||
func mutableCopy(with zone: NSZone? = nil) -> Any {
|
||||
return _mapUnmanaged { $0.mutableCopy(with: zone) }
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ public struct CharacterSet : ReferenceConvertible, Equatable, Hashable, SetAlgeb
|
||||
|
||||
private init(_bridged characterSet: NSCharacterSet) {
|
||||
// We must copy the input because it might be mutable; just like storing a value type in ObjC
|
||||
_wrapped = _SwiftNSCharacterSet(immutableObject: characterSet.copy())
|
||||
_wrapped = _SwiftNSCharacterSet(immutableObject: characterSet.copy() as AnyObject)
|
||||
}
|
||||
|
||||
/// Initialize an empty instance.
|
||||
|
||||
@@ -253,7 +253,7 @@ public struct Data : ReferenceConvertible, CustomStringConvertible, Equatable, H
|
||||
///
|
||||
/// - parameter reference: The instance of `NSData` that you wish to wrap. This instance will be copied by `struct Data`.
|
||||
public init(referencing reference: NSData) {
|
||||
_wrapped = _SwiftNSData(immutableObject: reference.copy())
|
||||
_wrapped = _SwiftNSData(immutableObject: reference.copy() as AnyObject)
|
||||
}
|
||||
|
||||
// -----------------------------------
|
||||
|
||||
@@ -40,7 +40,7 @@ extension FileManager {
|
||||
@available(OSX 10.6, iOS 4.0, *)
|
||||
public func replaceItemAt(_ originalItemURL: URL, withItemAt newItemURL: URL, backupItemName: String? = nil, options: FileManager.ItemReplacementOptions = []) throws -> NSURL? {
|
||||
var error: NSError? = nil
|
||||
if let result = NS_Swift_NSFileManager_replaceItemAtURL_withItemAtURL_backupItemName_options(self, originalItemURL as URL, newItemURL as URL, backupItemName, options, &error) {
|
||||
if let result = NS_Swift_NSFileManager_replaceItemAtURL_withItemAtURL_backupItemName_options(self, originalItemURL as NSURL, newItemURL as NSURL, backupItemName, options, &error) {
|
||||
return result
|
||||
}
|
||||
throw error!
|
||||
|
||||
@@ -95,7 +95,7 @@ extension String : _ObjectiveCBridgeable {
|
||||
// This method should not do anything extra except calling into the
|
||||
// implementation inside core. (These two entry points should be
|
||||
// equivalent.)
|
||||
return unsafeBitCast(_bridgeToObjectiveCImpl(), to: NSString.self)
|
||||
return unsafeBitCast(_bridgeToObjectiveCImpl() as AnyObject, to: NSString.self)
|
||||
}
|
||||
|
||||
public static func _forceBridgeFromObjectiveC(
|
||||
@@ -378,7 +378,7 @@ public let NSNotFound: Int = .max
|
||||
|
||||
extension NSArray : ExpressibleByArrayLiteral {
|
||||
/// Create an instance initialized with `elements`.
|
||||
public required convenience init(arrayLiteral elements: AnyObject...) {
|
||||
public required convenience init(arrayLiteral elements: Any...) {
|
||||
// Let bridging take care of it.
|
||||
self.init(array: elements)
|
||||
}
|
||||
@@ -405,7 +405,7 @@ extension Array : _ObjectiveCBridgeable {
|
||||
// and watchOS.
|
||||
self = Array(
|
||||
_immutableCocoaArray:
|
||||
unsafeBitCast(_cocoaArray.copy(), to: _NSArrayCore.self))
|
||||
unsafeBitCast(_cocoaArray.copy() as AnyObject, to: _NSArrayCore.self))
|
||||
}
|
||||
|
||||
public static func _isBridgedToObjectiveC() -> Bool {
|
||||
@@ -414,7 +414,7 @@ extension Array : _ObjectiveCBridgeable {
|
||||
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSArray {
|
||||
return unsafeBitCast(self._buffer._asCocoaArray(), to: NSArray.self)
|
||||
return unsafeBitCast(self._buffer._asCocoaArray() as AnyObject, to: NSArray.self)
|
||||
}
|
||||
|
||||
public static func _forceBridgeFromObjectiveC(
|
||||
@@ -455,10 +455,6 @@ extension Array : _ObjectiveCBridgeable {
|
||||
public static func _unconditionallyBridgeFromObjectiveC(
|
||||
_ source: NSArray?
|
||||
) -> Array {
|
||||
_precondition(
|
||||
Swift._isBridgedToObjectiveC(Element.self),
|
||||
"array element type is not bridged to Objective-C")
|
||||
|
||||
// `nil` has historically been used as a stand-in for an empty
|
||||
// array; map it to an empty array instead of failing.
|
||||
if _slowPath(source == nil) { return Array() }
|
||||
@@ -514,7 +510,8 @@ extension Dictionary {
|
||||
// and watchOS.
|
||||
self = Dictionary(
|
||||
_immutableCocoaDictionary:
|
||||
unsafeBitCast(_cocoaDictionary.copy(with: nil), to: _NSDictionary.self))
|
||||
unsafeBitCast(_cocoaDictionary.copy(with: nil) as AnyObject,
|
||||
to: _NSDictionary.self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,7 +519,8 @@ extension Dictionary {
|
||||
extension Dictionary : _ObjectiveCBridgeable {
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSDictionary {
|
||||
return unsafeBitCast(_bridgeToObjectiveCImpl(), to: NSDictionary.self)
|
||||
return unsafeBitCast(_bridgeToObjectiveCImpl() as AnyObject,
|
||||
to: NSDictionary.self)
|
||||
}
|
||||
|
||||
public static func _forceBridgeFromObjectiveC(
|
||||
@@ -538,7 +536,7 @@ extension Dictionary : _ObjectiveCBridgeable {
|
||||
if _isBridgedVerbatimToObjectiveC(Key.self) &&
|
||||
_isBridgedVerbatimToObjectiveC(Value.self) {
|
||||
result = [Key : Value](
|
||||
_cocoaDictionary: unsafeBitCast(d, to: _NSDictionary.self))
|
||||
_cocoaDictionary: unsafeBitCast(d as AnyObject, to: _NSDictionary.self))
|
||||
return
|
||||
}
|
||||
|
||||
@@ -546,8 +544,10 @@ extension Dictionary : _ObjectiveCBridgeable {
|
||||
// may not be backed by an NSDictionary.
|
||||
var builder = _DictionaryBuilder<Key, Value>(count: d.count)
|
||||
d.enumerateKeysAndObjects({
|
||||
(anyObjectKey: AnyObject, anyObjectValue: AnyObject,
|
||||
(anyKey: Any, anyValue: Any,
|
||||
stop: UnsafeMutablePointer<ObjCBool>) in
|
||||
let anyObjectKey = anyKey as AnyObject
|
||||
let anyObjectValue = anyValue as AnyObject
|
||||
builder.add(
|
||||
key: Swift._forceBridgeFromObjectiveC(anyObjectKey, Key.self),
|
||||
value: Swift._forceBridgeFromObjectiveC(anyObjectValue, Value.self))
|
||||
@@ -590,18 +590,18 @@ extension Dictionary : _ObjectiveCBridgeable {
|
||||
if _isBridgedVerbatimToObjectiveC(Key.self) &&
|
||||
_isBridgedVerbatimToObjectiveC(Value.self) {
|
||||
return [Key : Value](
|
||||
_cocoaDictionary: unsafeBitCast(d!, to: _NSDictionary.self))
|
||||
_cocoaDictionary: unsafeBitCast(d! as AnyObject, to: _NSDictionary.self))
|
||||
}
|
||||
|
||||
// `Dictionary<Key, Value>` where either `Key` or `Value` is a value type
|
||||
// may not be backed by an NSDictionary.
|
||||
var builder = _DictionaryBuilder<Key, Value>(count: d!.count)
|
||||
d!.enumerateKeysAndObjects({
|
||||
(anyObjectKey: AnyObject, anyObjectValue: AnyObject,
|
||||
(anyKey: Any, anyValue: Any,
|
||||
stop: UnsafeMutablePointer<ObjCBool>) in
|
||||
builder.add(
|
||||
key: Swift._forceBridgeFromObjectiveC(anyObjectKey, Key.self),
|
||||
value: Swift._forceBridgeFromObjectiveC(anyObjectValue, Value.self))
|
||||
key: Swift._forceBridgeFromObjectiveC(anyKey as AnyObject, Key.self),
|
||||
value: Swift._forceBridgeFromObjectiveC(anyValue as AnyObject, Value.self))
|
||||
})
|
||||
return builder.take()
|
||||
}
|
||||
@@ -644,14 +644,14 @@ final public class NSFastEnumerationIterator : IteratorProtocol {
|
||||
|
||||
var objects: [Unmanaged<AnyObject>?]
|
||||
|
||||
public func next() -> AnyObject? {
|
||||
public func next() -> Any? {
|
||||
if n == count {
|
||||
// FIXME: Is this check necessary before refresh()?
|
||||
if count == 0 { return nil }
|
||||
refresh()
|
||||
if count == 0 { return nil }
|
||||
}
|
||||
let next: AnyObject = state[0].itemsPtr![n]!
|
||||
let next: Any = state[0].itemsPtr![n]!
|
||||
n += 1
|
||||
return next
|
||||
}
|
||||
@@ -720,7 +720,7 @@ extension Set {
|
||||
// and watchOS.
|
||||
self = Set(
|
||||
_immutableCocoaSet:
|
||||
unsafeBitCast(_cocoaSet.copy(with: nil), to: _NSSet.self))
|
||||
unsafeBitCast(_cocoaSet.copy(with: nil) as AnyObject, to: _NSSet.self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -784,7 +784,7 @@ extension NSIndexSet : Sequence {
|
||||
extension Set : _ObjectiveCBridgeable {
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSSet {
|
||||
return unsafeBitCast(_bridgeToObjectiveCImpl(), to: NSSet.self)
|
||||
return unsafeBitCast(_bridgeToObjectiveCImpl() as AnyObject, to: NSSet.self)
|
||||
}
|
||||
|
||||
public static func _forceBridgeFromObjectiveC(_ s: NSSet, result: inout Set?) {
|
||||
@@ -804,9 +804,9 @@ extension Set : _ObjectiveCBridgeable {
|
||||
// an NSSet.
|
||||
var builder = _SetBuilder<Element>(count: s.count)
|
||||
s.enumerateObjects({
|
||||
(anyObjectMember: AnyObject, stop: UnsafeMutablePointer<ObjCBool>) in
|
||||
(anyMember: Any, stop: UnsafeMutablePointer<ObjCBool>) in
|
||||
builder.add(member: Swift._forceBridgeFromObjectiveC(
|
||||
anyObjectMember, Element.self))
|
||||
anyMember as AnyObject, Element.self))
|
||||
})
|
||||
result = builder.take()
|
||||
}
|
||||
@@ -836,16 +836,17 @@ extension Set : _ObjectiveCBridgeable {
|
||||
}
|
||||
|
||||
if _isBridgedVerbatimToObjectiveC(Element.self) {
|
||||
return Set<Element>(_cocoaSet: unsafeBitCast(s!, to: _NSSet.self))
|
||||
return Set<Element>(_cocoaSet: unsafeBitCast(s! as AnyObject,
|
||||
to: _NSSet.self))
|
||||
}
|
||||
|
||||
// `Set<Element>` where `Element` is a value type may not be backed by
|
||||
// an NSSet.
|
||||
var builder = _SetBuilder<Element>(count: s!.count)
|
||||
s!.enumerateObjects({
|
||||
(anyObjectMember: AnyObject, stop: UnsafeMutablePointer<ObjCBool>) in
|
||||
(anyMember: Any, stop: UnsafeMutablePointer<ObjCBool>) in
|
||||
builder.add(member: Swift._forceBridgeFromObjectiveC(
|
||||
anyObjectMember, Element.self))
|
||||
anyMember as AnyObject, Element.self))
|
||||
})
|
||||
return builder.take()
|
||||
}
|
||||
@@ -864,7 +865,7 @@ extension NSDictionary : Sequence {
|
||||
return _fastIterator.enumerable as! NSDictionary
|
||||
}
|
||||
|
||||
public func next() -> (key: AnyObject, value: AnyObject)? {
|
||||
public func next() -> (key: Any, value: Any)? {
|
||||
if let key = _fastIterator.next() {
|
||||
// Deliberately avoid the subscript operator in case the dictionary
|
||||
// contains non-copyable keys. This is rare since NSMutableDictionary
|
||||
@@ -1071,33 +1072,33 @@ extension NSMutableString {
|
||||
|
||||
extension NSArray {
|
||||
// Overlay: - (instancetype)initWithObjects:(id)firstObj, ...
|
||||
public convenience init(objects elements: AnyObject...) {
|
||||
public convenience init(objects elements: Any...) {
|
||||
self.init(array: elements)
|
||||
}
|
||||
}
|
||||
|
||||
extension NSOrderedSet {
|
||||
// - (instancetype)initWithObjects:(id)firstObj, ...
|
||||
public convenience init(objects elements: AnyObject...) {
|
||||
public convenience init(objects elements: Any...) {
|
||||
self.init(array: elements)
|
||||
}
|
||||
}
|
||||
|
||||
extension NSSet {
|
||||
// - (instancetype)initWithObjects:(id)firstObj, ...
|
||||
public convenience init(objects elements: AnyObject...) {
|
||||
public convenience init(objects elements: Any...) {
|
||||
self.init(array: elements)
|
||||
}
|
||||
}
|
||||
|
||||
extension NSSet : ExpressibleByArrayLiteral {
|
||||
public required convenience init(arrayLiteral elements: AnyObject...) {
|
||||
public required convenience init(arrayLiteral elements: Any...) {
|
||||
self.init(array: elements)
|
||||
}
|
||||
}
|
||||
|
||||
extension NSOrderedSet : ExpressibleByArrayLiteral {
|
||||
public required convenience init(arrayLiteral elements: AnyObject...) {
|
||||
public required convenience init(arrayLiteral elements: Any...) {
|
||||
self.init(array: elements)
|
||||
}
|
||||
}
|
||||
@@ -1248,20 +1249,20 @@ extension NSCoder {
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
public func decodeObject(of classes: [AnyClass]?, forKey key: String) -> AnyObject? {
|
||||
public func decodeObject(of classes: [AnyClass]?, forKey key: String) -> Any? {
|
||||
var classesAsNSObjects: NSSet? = nil
|
||||
if let theClasses = classes {
|
||||
classesAsNSObjects = NSSet(array: theClasses.map { $0 as AnyObject })
|
||||
}
|
||||
return NS_Swift_NSCoder_decodeObjectOfClassesForKey(self as AnyObject, classesAsNSObjects, key as AnyObject, nil)
|
||||
return NS_Swift_NSCoder_decodeObjectOfClassesForKey(self as AnyObject, classesAsNSObjects, key as AnyObject, nil).map { $0 as Any }
|
||||
}
|
||||
|
||||
@available(OSX 10.11, iOS 9.0, *)
|
||||
public func decodeTopLevelObject() throws -> AnyObject? {
|
||||
public func decodeTopLevelObject() throws -> Any? {
|
||||
var error: NSError?
|
||||
let result = NS_Swift_NSCoder_decodeObject(self as AnyObject, &error)
|
||||
try resolveError(error)
|
||||
return result
|
||||
return result.map { $0 as Any }
|
||||
}
|
||||
|
||||
@available(*, unavailable, renamed: "decodeTopLevelObject(forKey:)")
|
||||
@@ -1302,7 +1303,7 @@ extension NSCoder {
|
||||
}
|
||||
|
||||
@available(OSX 10.11, iOS 9.0, *)
|
||||
public func decodeTopLevelObject(of classes: [AnyClass]?, forKey key: String) throws -> AnyObject? {
|
||||
public func decodeTopLevelObject(of classes: [AnyClass]?, forKey key: String) throws -> Any? {
|
||||
var error: NSError? = nil
|
||||
var classesAsNSObjects: NSSet? = nil
|
||||
if let theClasses = classes {
|
||||
@@ -1310,7 +1311,7 @@ extension NSCoder {
|
||||
}
|
||||
let result = NS_Swift_NSCoder_decodeObjectOfClassesForKey(self as AnyObject, classesAsNSObjects, key as AnyObject, &error)
|
||||
try resolveError(error)
|
||||
return result
|
||||
return result.map { $0 as Any }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ public struct Locale : CustomStringConvertible, CustomDebugStringConvertible, Ha
|
||||
/// For example, in the "en" locale, the result for `.buddhist` is `"Buddhist Calendar"`.
|
||||
public func localizedString(for calendarIdentifier: Calendar.Identifier) -> String? {
|
||||
// NSLocale doesn't export a constant for this
|
||||
let result = CFLocaleCopyDisplayNameForPropertyValue(unsafeBitCast(_wrapped, to: CFLocale.self), .calendarIdentifier, Calendar._toNSCalendarIdentifier(calendarIdentifier)) as String
|
||||
let result = CFLocaleCopyDisplayNameForPropertyValue(unsafeBitCast(_wrapped, to: CFLocale.self), .calendarIdentifier, Calendar._toNSCalendarIdentifier(calendarIdentifier).rawValue as CFString) as String
|
||||
return result
|
||||
}
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ public protocol CustomNSError : Error {
|
||||
var errorCode: Int { get }
|
||||
|
||||
/// The user-info dictionary.
|
||||
var errorUserInfo: [String : AnyObject] { get }
|
||||
var errorUserInfo: [String : Any] { get }
|
||||
}
|
||||
|
||||
public extension Error where Self : CustomNSError {
|
||||
@@ -191,7 +191,7 @@ public func _swift_Foundation_getErrorDefaultUserInfo(_ error: Error)
|
||||
}
|
||||
|
||||
// Populate the user-info dictionary
|
||||
var result: [String : AnyObject]
|
||||
var result: [String : Any]
|
||||
|
||||
// Initialize with custom user-info.
|
||||
if let customNSError = error as? CustomNSError {
|
||||
@@ -205,19 +205,19 @@ public func _swift_Foundation_getErrorDefaultUserInfo(_ error: Error)
|
||||
if !hasUserInfoValueProvider,
|
||||
let localizedError = error as? LocalizedError {
|
||||
if let description = localizedError.errorDescription {
|
||||
result[NSLocalizedDescriptionKey] = description as AnyObject
|
||||
result[NSLocalizedDescriptionKey] = description
|
||||
}
|
||||
|
||||
if let reason = localizedError.failureReason {
|
||||
result[NSLocalizedFailureReasonErrorKey] = reason as AnyObject
|
||||
result[NSLocalizedFailureReasonErrorKey] = reason
|
||||
}
|
||||
|
||||
if let suggestion = localizedError.recoverySuggestion {
|
||||
result[NSLocalizedRecoverySuggestionErrorKey] = suggestion as AnyObject
|
||||
result[NSLocalizedRecoverySuggestionErrorKey] = suggestion
|
||||
}
|
||||
|
||||
if let helpAnchor = localizedError.helpAnchor {
|
||||
result[NSHelpAnchorErrorKey] = helpAnchor as AnyObject
|
||||
result[NSHelpAnchorErrorKey] = helpAnchor
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ public func _swift_Foundation_getErrorDefaultUserInfo(_ error: Error)
|
||||
if !hasUserInfoValueProvider,
|
||||
let recoverableError = error as? RecoverableError {
|
||||
result[NSLocalizedRecoveryOptionsErrorKey] =
|
||||
recoverableError.recoveryOptions as AnyObject
|
||||
recoverableError.recoveryOptions
|
||||
result[NSRecoveryAttempterErrorKey] = _NSErrorRecoveryAttempter()
|
||||
}
|
||||
|
||||
@@ -240,7 +240,7 @@ public func _swift_Foundation_getErrorDefaultUserInfo(_ error: Error)
|
||||
extension NSError : Error {
|
||||
public var _domain: String { return domain }
|
||||
public var _code: Int { return code }
|
||||
public var _userInfo: AnyObject? { return userInfo as AnyObject }
|
||||
public var _userInfo: Any? { return userInfo }
|
||||
}
|
||||
|
||||
extension CFError : Error {
|
||||
@@ -252,8 +252,8 @@ extension CFError : Error {
|
||||
return CFErrorGetCode(self)
|
||||
}
|
||||
|
||||
public var _userInfo: AnyObject? {
|
||||
return CFErrorCopyUserInfo(self) as AnyObject?
|
||||
public var _userInfo: Any? {
|
||||
return CFErrorCopyUserInfo(self) as Any
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,6 +388,16 @@ public protocol _BridgedStoredNSError :
|
||||
init(_nsError error: NSError)
|
||||
}
|
||||
|
||||
/// TODO: Better way to do this?
|
||||
internal func _stringDictToNSObjectDict(_ input: [String : Any])
|
||||
-> [NSObject : Any] {
|
||||
var result: [NSObject : Any] = [:]
|
||||
for (k, v) in input {
|
||||
result[k as NSString] = v
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/// Various helper implementations for _BridgedStoredNSError
|
||||
public extension _BridgedStoredNSError
|
||||
where Code: RawRepresentable, Code.RawValue: SignedInteger {
|
||||
@@ -398,15 +408,15 @@ public extension _BridgedStoredNSError
|
||||
|
||||
/// Initialize an error within this domain with the given ``code``
|
||||
/// and ``userInfo``.
|
||||
public init(_ code: Code, userInfo: [String : AnyObject] = [:]) {
|
||||
public init(_ code: Code, userInfo: [String : Any] = [:]) {
|
||||
self.init(_nsError: NSError(domain: Self._nsErrorDomain,
|
||||
code: numericCast(code.rawValue),
|
||||
userInfo: userInfo))
|
||||
userInfo: _stringDictToNSObjectDict(userInfo)))
|
||||
}
|
||||
|
||||
/// The user-info dictionary for an error that was bridged from
|
||||
/// NSError.
|
||||
var userInfo: [String : AnyObject] { return errorUserInfo }
|
||||
var userInfo: [String : Any] { return errorUserInfo }
|
||||
}
|
||||
|
||||
/// Various helper implementations for _BridgedStoredNSError
|
||||
@@ -419,10 +429,10 @@ public extension _BridgedStoredNSError
|
||||
|
||||
/// Initialize an error within this domain with the given ``code``
|
||||
/// and ``userInfo``.
|
||||
public init(_ code: Code, userInfo: [String : AnyObject] = [:]) {
|
||||
public init(_ code: Code, userInfo: [String : Any] = [:]) {
|
||||
self.init(_nsError: NSError(domain: Self._nsErrorDomain,
|
||||
code: numericCast(code.rawValue),
|
||||
userInfo: userInfo))
|
||||
userInfo: _stringDictToNSObjectDict(userInfo)))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,8 +458,8 @@ public extension _BridgedStoredNSError {
|
||||
|
||||
var errorCode: Int { return _nsError.code }
|
||||
|
||||
var errorUserInfo: [String : AnyObject] {
|
||||
var result: [String : AnyObject] = [:]
|
||||
var errorUserInfo: [String : Any] {
|
||||
var result: [String : Any] = [:]
|
||||
for (key, value) in _nsError.userInfo {
|
||||
guard let stringKey = key as? String else { continue }
|
||||
result[stringKey] = value
|
||||
@@ -518,29 +528,29 @@ public struct CocoaError : _BridgedStoredNSError {
|
||||
}
|
||||
|
||||
public extension CocoaError {
|
||||
private var _userInfo: [NSObject : AnyObject] {
|
||||
private var _nsUserInfo: [NSObject : Any] {
|
||||
return (self as NSError).userInfo
|
||||
}
|
||||
|
||||
/// The file path associated with the error, if any.
|
||||
var filePath: String? {
|
||||
return _userInfo[NSFilePathErrorKey] as? String
|
||||
return _nsUserInfo[NSFilePathErrorKey as NSString] as? String
|
||||
}
|
||||
|
||||
/// The string encoding associated with this error, if any.
|
||||
var stringEncoding: String.Encoding? {
|
||||
return (_userInfo[NSStringEncodingErrorKey] as? NSNumber)
|
||||
return (_nsUserInfo[NSStringEncodingErrorKey as NSString] as? NSNumber)
|
||||
.map { String.Encoding(rawValue: $0.uintValue) }
|
||||
}
|
||||
|
||||
/// The underlying error behind this error, if any.
|
||||
var underlying: Error? {
|
||||
return _userInfo[NSUnderlyingErrorKey] as? Error
|
||||
return _nsUserInfo[NSUnderlyingErrorKey as NSString] as? Error
|
||||
}
|
||||
|
||||
/// The URL associated with this error, if any.
|
||||
var url: URL? {
|
||||
return _userInfo[NSURLErrorKey] as? URL
|
||||
return _nsUserInfo[NSURLErrorKey as NSString] as? URL
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1319,23 +1329,23 @@ public struct URLError : _BridgedStoredNSError {
|
||||
}
|
||||
|
||||
public extension URLError {
|
||||
private var _userInfo: [NSObject : AnyObject] {
|
||||
private var _nsUserInfo: [NSObject : Any] {
|
||||
return (self as NSError).userInfo
|
||||
}
|
||||
|
||||
/// The URL which caused a load to fail.
|
||||
public var failingURL: URL? {
|
||||
return _userInfo[NSURLErrorFailingURLErrorKey] as? URL
|
||||
return _nsUserInfo[NSURLErrorFailingURLErrorKey as NSString] as? URL
|
||||
}
|
||||
|
||||
/// The string for the URL which caused a load to fail.
|
||||
public var failureURLString: String? {
|
||||
return _userInfo[NSURLErrorFailingURLStringErrorKey] as? String
|
||||
return _nsUserInfo[NSURLErrorFailingURLStringErrorKey as NSString] as? String
|
||||
}
|
||||
|
||||
/// The state of a failed SSL handshake.
|
||||
public var failureURLPeerTrust: SecTrust? {
|
||||
if let secTrust = _userInfo[NSURLErrorFailingURLPeerTrustErrorKey] {
|
||||
if let secTrust = _nsUserInfo[NSURLErrorFailingURLPeerTrustErrorKey as NSString] {
|
||||
return (secTrust as! SecTrust)
|
||||
}
|
||||
|
||||
|
||||
@@ -1170,7 +1170,7 @@ extension String {
|
||||
/// Parses the `String` as a text representation of a
|
||||
/// property list, returning an NSString, NSData, NSArray, or
|
||||
/// NSDictionary object, according to the topmost element.
|
||||
public func propertyList() -> AnyObject {
|
||||
public func propertyList() -> Any {
|
||||
return _ns.propertyList()
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public struct Notification : ReferenceConvertible, Equatable, Hashable {
|
||||
/// An object that the poster wishes to send to observers.
|
||||
///
|
||||
/// Typically this is the object that posted the notification.
|
||||
public var object: AnyObject?
|
||||
public var object: Any?
|
||||
|
||||
/// Storage for values or objects related to this notification.
|
||||
public var userInfo: [String : Any]?
|
||||
@@ -39,7 +39,7 @@ public struct Notification : ReferenceConvertible, Equatable, Hashable {
|
||||
/// Initialize a new `Notification`.
|
||||
///
|
||||
/// The default value for `userInfo` is nil.
|
||||
public init(name: Name, object: AnyObject? = nil, userInfo: [String : Any]? = nil) {
|
||||
public init(name: Name, object: Any? = nil, userInfo: [String : Any]? = nil) {
|
||||
self.name = name
|
||||
self.object = object
|
||||
self.userInfo = userInfo
|
||||
@@ -69,7 +69,7 @@ public struct Notification : ReferenceConvertible, Equatable, Hashable {
|
||||
}
|
||||
if let lhsObj = lhs.object {
|
||||
if let rhsObj = rhs.object {
|
||||
if lhsObj !== rhsObj {
|
||||
if lhsObj as AnyObject !== rhsObj as AnyObject {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
@@ -106,7 +106,7 @@ extension Notification : _ObjectiveCBridgeable {
|
||||
@_semantics("convertToObjectiveC")
|
||||
public func _bridgeToObjectiveC() -> NSNotification {
|
||||
if let info = userInfo {
|
||||
return __NSNotificationCreate(name.rawValue as NSString, object, _NSUserInfoDictionary.bridgeValue(from: info))
|
||||
return __NSNotificationCreate(name.rawValue as NSString, object.map { $0 as AnyObject }, _NSUserInfoDictionary.bridgeValue(from: info))
|
||||
}
|
||||
|
||||
return NSNotification(name: name, object: object, userInfo: nil)
|
||||
|
||||
@@ -77,7 +77,7 @@ public struct TimeZone : CustomStringConvertible, CustomDebugStringConvertible,
|
||||
/// - parameter seconds: The number of seconds from GMT.
|
||||
/// - returns: A time zone, or `nil` if a valid time zone could not be created from `seconds`.
|
||||
public init?(secondsFromGMT seconds: Int) {
|
||||
if let r = NSTimeZone(forSecondsFromGMT: seconds) as TimeZone? {
|
||||
if let r = NSTimeZone(forSecondsFromGMT: seconds) as NSTimeZone? {
|
||||
_wrapped = r
|
||||
_autoupdating = false
|
||||
} else {
|
||||
|
||||
@@ -36,7 +36,7 @@ public struct URLThumbnailSizeKey : RawRepresentable, Hashable {
|
||||
As a convenience, volume resource values can be requested from any file system URL. The value returned will reflect the property value for the volume on which the resource is located.
|
||||
*/
|
||||
public struct URLResourceValues {
|
||||
private var _values: [URLResourceKey: AnyObject]
|
||||
private var _values: [URLResourceKey: Any]
|
||||
private var _keys: Set<URLResourceKey>
|
||||
|
||||
public init() {
|
||||
@@ -44,7 +44,7 @@ public struct URLResourceValues {
|
||||
_keys = []
|
||||
}
|
||||
|
||||
private init(keys: Set<URLResourceKey>, values: [URLResourceKey: AnyObject]) {
|
||||
private init(keys: Set<URLResourceKey>, values: [URLResourceKey: Any]) {
|
||||
_values = values
|
||||
_keys = keys
|
||||
}
|
||||
@@ -63,7 +63,7 @@ public struct URLResourceValues {
|
||||
return (_values[key] as? NSNumber)?.intValue
|
||||
}
|
||||
|
||||
private mutating func _set(_ key : URLResourceKey, newValue : AnyObject?) {
|
||||
private mutating func _set(_ key : URLResourceKey, newValue : Any?) {
|
||||
_keys.insert(key)
|
||||
_values[key] = newValue
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public struct URLResourceValues {
|
||||
/// A loosely-typed dictionary containing all keys and values.
|
||||
///
|
||||
/// If you have set temporary keys or non-standard keys, you can find them in here.
|
||||
public var allValues : [URLResourceKey : AnyObject] {
|
||||
public var allValues : [URLResourceKey : Any] {
|
||||
return _values
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ public struct URLResourceValues {
|
||||
#if os(OSX)
|
||||
/// The quarantine properties as defined in LSQuarantine.h. To remove quarantine information from a file, pass `nil` as the value when setting this property.
|
||||
@available(OSX 10.10, *)
|
||||
public var quarantineProperties: [String : AnyObject]? {
|
||||
public var quarantineProperties: [String : Any]? {
|
||||
get { return _get(.quarantinePropertiesKey) }
|
||||
set { _set(.quarantinePropertiesKey, newValue: newValue as NSObject?) }
|
||||
}
|
||||
@@ -1025,7 +1025,7 @@ public struct URL : ReferenceConvertible, CustomStringConvertible, Equatable {
|
||||
/// Temporary resource values are for client use. Temporary resource values exist only in memory and are never written to the resource's backing store. Once set, a temporary resource value can be copied from the URL object with `func resourceValues(forKeys:)`. The values are stored in the loosely-typed `allValues` dictionary property.
|
||||
///
|
||||
/// To remove a temporary resource value from the URL object, use `func removeCachedResourceValue(forKey:)`. Care should be taken to ensure the key that identifies a temporary resource value is unique and does not conflict with system defined keys (using reverse domain name notation in your temporary resource value keys is recommended). This method is currently applicable only to URLs for file system resources.
|
||||
public mutating func setTemporaryResourceValue(_ value : AnyObject, forKey key: URLResourceKey) {
|
||||
public mutating func setTemporaryResourceValue(_ value : Any, forKey key: URLResourceKey) {
|
||||
_url.setTemporaryResourceValue(value, forKey: key)
|
||||
}
|
||||
|
||||
@@ -1104,7 +1104,7 @@ public struct URL : ReferenceConvertible, CustomStringConvertible, Equatable {
|
||||
// Future readers: file reference URL here is not the same as playgrounds "file reference"
|
||||
if url.isFileReferenceURL() {
|
||||
// Convert to a file path URL, or use an invalid scheme
|
||||
return url.filePathURL ?? URL(string: "com-apple-unresolvable-file-reference-url:")!
|
||||
return (url.filePathURL ?? URL(string: "com-apple-unresolvable-file-reference-url:")!) as NSURL
|
||||
} else {
|
||||
return url
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ internal class _NSUserInfoDictionaryKeyEnumerator : NSEnumerator {
|
||||
}
|
||||
|
||||
@objc
|
||||
internal override func nextObject() -> AnyObject? {
|
||||
internal override func nextObject() -> Any? {
|
||||
if let next = _objcKeyGenerator?.next() {
|
||||
return next
|
||||
} else {
|
||||
@@ -59,7 +59,7 @@ internal class _NSUserInfoDictionary : NSMutableDictionary {
|
||||
internal convenience init(dictionary dict: NSDictionary) {
|
||||
self.init()
|
||||
dict.enumerateKeysAndObjects(options: []) { k, v, stop in
|
||||
_objc[k as! NSObject] = v
|
||||
_objc[k as! NSObject] = v as AnyObject
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ internal class _NSUserInfoDictionary : NSMutableDictionary {
|
||||
}
|
||||
|
||||
@objc
|
||||
internal override func object(forKey aKey: AnyObject) -> AnyObject? {
|
||||
internal override func object(forKey aKey: Any) -> Any? {
|
||||
if let key = aKey as? String {
|
||||
if let val = _objc[key as NSString] {
|
||||
return val
|
||||
@@ -86,17 +86,17 @@ internal class _NSUserInfoDictionary : NSMutableDictionary {
|
||||
}
|
||||
|
||||
@objc
|
||||
internal override func copy(with zone: NSZone?) -> AnyObject {
|
||||
internal override func copy(with zone: NSZone?) -> Any {
|
||||
return self
|
||||
}
|
||||
|
||||
@objc
|
||||
internal override func mutableCopy(with zone: NSZone?) -> AnyObject {
|
||||
internal override func mutableCopy(with zone: NSZone?) -> Any {
|
||||
return _NSUserInfoDictionary(objc: _objc, swift: _swift)
|
||||
}
|
||||
|
||||
@objc
|
||||
internal override func removeObject(forKey key: AnyObject) {
|
||||
internal override func removeObject(forKey key: Any) {
|
||||
if let k = key as? String {
|
||||
_objc[k as NSString] = nil
|
||||
_swift[k as NSString] = nil
|
||||
@@ -104,7 +104,7 @@ internal class _NSUserInfoDictionary : NSMutableDictionary {
|
||||
}
|
||||
|
||||
@objc
|
||||
internal override func setObject(_ anObject: AnyObject, forKey aKey: NSCopying) {
|
||||
internal override func setObject(_ anObject: Any, forKey aKey: NSCopying) {
|
||||
if let key = aKey as? String {
|
||||
if let obj = anObject as? NSObject {
|
||||
if let box = obj as? _NSSwiftUserInfoItem {
|
||||
@@ -152,6 +152,7 @@ internal class _NSUserInfoDictionary : NSMutableDictionary {
|
||||
return true
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
internal static func bridgeValue(from source: [String : Any]) -> AnyObject {
|
||||
var objc = [NSObject : AnyObject]()
|
||||
var swift = [NSObject : Any]()
|
||||
@@ -168,6 +169,7 @@ internal class _NSUserInfoDictionary : NSMutableDictionary {
|
||||
return _NSUserInfoDictionary(objc: objc, swift: swift)
|
||||
}
|
||||
|
||||
@nonobjc
|
||||
internal static func bridgeValue(from source: [NSObject : Any]) -> AnyObject {
|
||||
var objc = [NSObject : AnyObject]()
|
||||
var swift = [NSObject : Any]()
|
||||
|
||||
Reference in New Issue
Block a user