File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -95,6 +95,12 @@ - (id)copyWithZone:(NSZone *)zone {
95
95
return [self retain ];
96
96
}
97
97
98
+ - (Class )classForCoder {
99
+ // This is a runtime-private subclass. When archiving or unarchiving, do so
100
+ // as an NSError.
101
+ return [NSError class ];
102
+ }
103
+
98
104
@end
99
105
100
106
Class swift::getNSErrorClass () {
Original file line number Diff line number Diff line change @@ -68,6 +68,24 @@ ErrorProtocolBridgingTests.test("NSCopying") {
68
68
}
69
69
}
70
70
71
+ func archiveAndUnarchiveObject< T: NSCoding where T: NSObject > (
72
+ _ object: T
73
+ ) -> T ? {
74
+ let unarchiver = NSKeyedUnarchiver ( forReadingWith:
75
+ NSKeyedArchiver . archivedData ( withRootObject: object)
76
+ )
77
+ unarchiver. requiresSecureCoding = true
78
+ return unarchiver. decodeObjectOfClass ( T . self, forKey: " root " )
79
+ }
80
+ ErrorProtocolBridgingTests . test ( " NSCoding " ) {
81
+ autoreleasepool {
82
+ let orig = EnumError . ReallyBadError as NSError
83
+ let unarchived = archiveAndUnarchiveObject ( orig) !
84
+ expectEqual ( orig, unarchived)
85
+ expectTrue ( unarchived. dynamicType == NSError . self)
86
+ }
87
+ }
88
+
71
89
ErrorProtocolBridgingTests . test ( " NSError-to-enum bridging " ) {
72
90
NoisyErrorLifeCount = 0
73
91
NoisyErrorDeathCount = 0
You can’t perform that action at this time.
0 commit comments