Skip to content

Commit f749c87

Browse files
committed
Convert some uses of [String:AnyObject] to [String:Any]
This allows us to use the Swift String as a value in these dictionary types instead of forcing a conversion to NSString.
1 parent 9dc70a7 commit f749c87

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

Foundation/FoundationErrors.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public extension NSCocoaError {
249249
import Glibc
250250
#endif
251251

252-
internal func _NSErrorWithErrno(posixErrno : Int32, reading : Bool, path : String? = nil, url : NSURL? = nil, extraUserInfo : [String : AnyObject]? = nil) -> NSError {
252+
internal func _NSErrorWithErrno(posixErrno : Int32, reading : Bool, path : String? = nil, url : NSURL? = nil, extraUserInfo : [String : Any]? = nil) -> NSError {
253253
var cocoaError : NSCocoaError
254254
if reading {
255255
switch posixErrno {
@@ -271,7 +271,7 @@ internal func _NSErrorWithErrno(posixErrno : Int32, reading : Bool, path : Strin
271271
}
272272
}
273273

274-
var userInfo = extraUserInfo ?? [String : AnyObject]()
274+
var userInfo = extraUserInfo ?? [String : Any]()
275275
if let path = path {
276276
userInfo[NSFilePathErrorKey] = path._nsObject
277277
} else if let url = url {

Foundation/NSBundle.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,19 @@ public class NSBundle : NSObject {
156156
// MARK: - Other
157157

158158
public var bundleIdentifier: String? { NSUnimplemented() }
159-
public var infoDictionary: [String : AnyObject]? { NSUnimplemented() }
160-
public var localizedInfoDictionary: [String : AnyObject]? { NSUnimplemented() }
161-
public func objectForInfoDictionaryKey(key: String) -> AnyObject? { NSUnimplemented() }
159+
160+
/// - Experiment: This is a draft API currently under consideration for official import into Foundation
161+
/// - Note: This API differs from Darwin because it uses [String : Any] as a type instead of [String : AnyObject]. This allows the use of Swift value types.
162+
public var infoDictionary: [String : Any]? { NSUnimplemented() }
163+
164+
/// - Experiment: This is a draft API currently under consideration for official import into Foundation
165+
/// - Note: This API differs from Darwin because it uses [String : Any] as a type instead of [String : AnyObject]. This allows the use of Swift value types.
166+
public var localizedInfoDictionary: [String : Any]? { NSUnimplemented() }
167+
168+
/// - Experiment: This is a draft API currently under consideration for official import into Foundation
169+
/// - Note: This API differs from Darwin because it uses [String : Any] as a type instead of [String : AnyObject]. This allows the use of Swift value types.
170+
public func objectForInfoDictionaryKey(key: String) -> Any? { NSUnimplemented() }
171+
162172
public func classNamed(className: String) -> AnyClass? { NSUnimplemented() }
163173
public var principalClass: AnyClass? { NSUnimplemented() }
164174
public var preferredLocalizations: [String] { NSUnimplemented() }

Foundation/NSError.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,13 @@ public class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
4242
// ErrorType forbids this being internal
4343
public var _domain: String
4444
public var _code: Int
45-
public var _userInfo: [String : AnyObject]?
46-
public init(domain: String, code: Int, userInfo dict: [String : AnyObject]?) {
45+
/// - Experiment: This is a draft API currently under consideration for official import into Foundation
46+
/// - Note: This API differs from Darwin because it uses [String : Any] as a type instead of [String : AnyObject]. This allows the use of Swift value types.
47+
private var _userInfo: [String : Any]?
48+
49+
/// - Experiment: This is a draft API currently under consideration for official import into Foundation
50+
/// - Note: This API differs from Darwin because it uses [String : Any] as a type instead of [String : AnyObject]. This allows the use of Swift value types.
51+
public init(domain: String, code: Int, userInfo dict: [String : Any]?) {
4752
_domain = domain
4853
_code = code
4954
_userInfo = dict
@@ -78,12 +83,14 @@ public class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
7883
}
7984
}
8085

81-
public var userInfo: [String : AnyObject] {
86+
/// - Experiment: This is a draft API currently under consideration for official import into Foundation
87+
/// - Note: This API differs from Darwin because it uses [String : Any] as a type instead of [String : AnyObject]. This allows the use of Swift value types.
88+
public var userInfo: [String : Any] {
8289
get {
8390
if let info = _userInfo {
8491
return info
8592
} else {
86-
return Dictionary<String, AnyObject>()
93+
return Dictionary<String, Any>()
8794
}
8895
}
8996
}
@@ -116,7 +123,7 @@ public class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
116123

117124
public var recoveryAttempter: AnyObject? {
118125
get {
119-
return userInfo[NSRecoveryAttempterErrorKey]
126+
return userInfo[NSRecoveryAttempterErrorKey] as? AnyObject
120127
}
121128
}
122129

0 commit comments

Comments
 (0)