Skip to content

Commit ac6a3f6

Browse files
committed
This was mistakenly relying on a Darwin-style bridged cast. So…:
… only fetch values that are objects — it makes a new warning happen on Darwin that I can't silence, but it will work on both platforms and without warnings on Linux.
1 parent 0995aa9 commit ac6a3f6

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Foundation/UserDefaults.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,15 @@ open class UserDefaults: NSObject {
268268
}
269269

270270
open func register(defaults registrationDictionary: [String : Any]) {
271-
registeredDefaults.merge(registrationDictionary.mapValues { _SwiftValue.fetch(nonOptional: $0 as AnyObject) }, uniquingKeysWith: { $1 })
271+
registeredDefaults.merge(registrationDictionary.mapValues { value in
272+
// This line will produce a 'Conditional cast always succeeds' warning on Darwin, since Darwin has bridging casts of any value to an object,
273+
// but is required for non-Darwin to work correctly, since that platform _doesn't_ have bridging casts of that kind for now.
274+
if let object = value as? AnyObject {
275+
return _SwiftValue.fetch(nonOptional: object)
276+
} else {
277+
return value
278+
}
279+
}, uniquingKeysWith: { $1 })
272280
}
273281

274282
open func addSuite(named suiteName: String) {

0 commit comments

Comments
 (0)