You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Added missing API: `DecodingFailurePolicy.raiseException`. It is now the default like on Darwin.
- Match Darwin behavior while decoding if you decode without raising exceptions.
- `decodeTopLevel…` variants are noted unavailable on swift-corelibs-foundation, with rationale and replacement directions.
Swift doesn’t have exceptions, and it used to define `.setErrorAndReturn` as the defaults. However, until very recently `failWithError(_:)` was unimplemented and trapped with a fatal error, effectively meaning that all coding failures were behaving as if `.raiseException` was set in a Darwin Swift-only app: by crashing.
Since code written to 4.x-5.0 may be relying on this behavior, we make it explicit and consistent with Darwin: there is now a `.raiseException` constant, it’s the default, and it fails with a fatal error in `failWithError(_:)`. The new secure initializers (at swiftlang#2102) set `.setErrorAndReturn` just like on Darwin, and thus won’t raise and instead just thrown an error.
Tests will be added.
fatalError("This method is only implemented for coders which allowKeyedCoding.")
205
+
}
206
+
207
+
if requiresSecureCoding {
208
+
NSRequiresConcreteImplementation()
209
+
}else{
210
+
returndecodeObject(forKey: key)
211
+
}
203
212
}
204
213
214
+
// ----- Top-level decoding -----
215
+
216
+
/*
217
+
On Darwin, if a coder's .decodingFailurePolicy is .raiseException, ObjC exceptions are used to interrupt execution of your init(coder:) initializer when a failure occurs during decoding.
218
+
219
+
The …TopLevel… methods below are documented to:
220
+
- interrupt your init(coder:) execution and immediately unwind the stack if a decoding error occurs with your .decodingFailurePolicy set to .raiseException, and
221
+
- still return with a thrown error, and continue program execution.
222
+
223
+
This isn't possible in swift-corelibs-foundation, where ObjC exceptions are unavailable; either program execution is immediately interrupted, or an error is thrown, but not both. To port your code to swift-corelibs-foundations, use the replacements noted below.
224
+
*/
225
+
226
+
@available(*, unavailable, message:"The behavior of this method isn't supported in swift-corelibs-foundation. You can use decodeObject() instead on all platforms. If you would like an error to be thrown, use .decodingFailurePolicy = .setErrorAndReturn, and check the .error property.", renamed:"decodeObject()")
205
227
openfunc decodeTopLevelObject()throws->Any?{
206
-
NSUnimplemented()
228
+
NSUnsupported()
207
229
}
208
230
231
+
@available(*, unavailable, message:"The behavior of this method isn't supported in swift-corelibs-foundation. You can use decodeObject(forKey:) instead on all platforms. If you would like an error to be thrown, use .decodingFailurePolicy = .setErrorAndReturn, and check the .error property.", renamed:"decodeObject(forKey:)")
@available(*, unavailable, message:"The behavior of this method isn't supported in swift-corelibs-foundation. You can use decodeObject(of:forKey:) instead on all platforms. If you would like an error to be thrown, use .decodingFailurePolicy = .setErrorAndReturn, and check the .error property.", renamed:"decodeObject(of:forKey:)")
/// Decodes an top-level object for the key, restricted to the specified
@@ -225,10 +249,13 @@ open class NSCoder : NSObject {
225
249
/// - classes: An array of the expected classes.
226
250
/// - key: The code key.
227
251
/// - Returns: The decoded object.
252
+
@available(*, unavailable, message:"The behavior of this method isn't supported in swift-corelibs-foundation. You can use decodeObject(of:forKey:) instead on all platforms. If you would like an error to be thrown, use .decodingFailurePolicy = .setErrorAndReturn, and check the .error property.", renamed:"decodeObject(of:forKey:)")
0 commit comments