@@ -106,12 +106,52 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
106
106
return unsafeBitCast ( self , CFCalendarRef . self)
107
107
}
108
108
109
- public required init ? ( coder aDecoder: NSCoder ) {
110
- NSUnimplemented ( )
109
+ public convenience required init ? ( coder aDecoder: NSCoder ) {
110
+ if aDecoder. allowsKeyedCoding {
111
+ guard let calendarIdentifier = aDecoder. decodeObjectOfClass ( NSString . self, forKey: " NS.identifier " ) else {
112
+ return nil
113
+ }
114
+
115
+ self . init ( calendarIdentifier: calendarIdentifier. bridge ( ) )
116
+
117
+ if let timeZone = aDecoder. decodeObjectOfClass ( NSTimeZone . self, forKey: " NS.timezone " ) {
118
+ self . timeZone = timeZone
119
+ }
120
+ if let locale = aDecoder. decodeObjectOfClass ( NSLocale . self, forKey: " NS.locale " ) {
121
+ self . locale = locale
122
+ }
123
+ self . firstWeekday = aDecoder. decodeIntegerForKey ( " NS.firstwkdy " )
124
+ self . minimumDaysInFirstWeek = aDecoder. decodeIntegerForKey ( " NS.mindays " )
125
+ if let startDate = aDecoder. decodeObjectOfClass ( NSDate . self, forKey: " NS.gstartdate " ) {
126
+ self . _startDate = startDate
127
+ }
128
+ } else {
129
+ NSUnimplemented ( )
130
+ }
131
+ }
132
+
133
+ private var _startDate : NSDate ? {
134
+ get {
135
+ return CFCalendarCopyGregorianStartDate ( self . _cfObject) ? . _nsObject
136
+ }
137
+ set {
138
+ if let startDate = newValue {
139
+ CFCalendarSetGregorianStartDate ( self . _cfObject, startDate. _cfObject)
140
+ }
141
+ }
111
142
}
112
143
113
144
public func encodeWithCoder( aCoder: NSCoder ) {
114
- NSUnimplemented ( )
145
+ if aCoder. allowsKeyedCoding {
146
+ aCoder. encodeObject ( self . calendarIdentifier. bridge ( ) , forKey: " NS.identifier " )
147
+ aCoder. encodeObject ( self . timeZone, forKey: " NS.timezone " )
148
+ aCoder. encodeObject ( self . locale, forKey: " NS.locale " )
149
+ aCoder. encodeInteger ( self . firstWeekday, forKey: " NS.firstwkdy " )
150
+ aCoder. encodeInteger ( self . minimumDaysInFirstWeek, forKey: " NS.mindays " )
151
+ aCoder. encodeObject ( self . _startDate, forKey: " NS.gstartdate " ) ;
152
+ } else {
153
+ NSUnimplemented ( )
154
+ }
115
155
}
116
156
117
157
static public func supportsSecureCoding( ) -> Bool {
@@ -171,7 +211,12 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
171
211
_CFDeinit ( self )
172
212
}
173
213
174
- public var calendarIdentifier : String { NSUnimplemented ( ) }
214
+ public var calendarIdentifier : String {
215
+ get {
216
+ return CFCalendarGetIdentifier ( _cfObject) . _swiftObject
217
+ }
218
+ }
219
+
175
220
/*@NSCopying*/ public var locale : NSLocale ? {
176
221
get {
177
222
return CFCalendarCopyLocale ( _cfObject) . _nsObject
@@ -1214,12 +1259,54 @@ public class NSDateComponents : NSObject, NSCopying, NSSecureCoding {
1214
1259
return false
1215
1260
}
1216
1261
1217
- public required init ? ( coder aDecoder: NSCoder ) {
1218
- NSUnimplemented ( )
1262
+ public convenience required init ? ( coder aDecoder: NSCoder ) {
1263
+ if aDecoder. allowsKeyedCoding {
1264
+ self . init ( )
1265
+
1266
+ self . era = aDecoder. decodeIntegerForKey ( " NS.era " )
1267
+ self . year = aDecoder. decodeIntegerForKey ( " NS.year " )
1268
+ self . quarter = aDecoder. decodeIntegerForKey ( " NS.quarter " )
1269
+ self . month = aDecoder. decodeIntegerForKey ( " NS.month " )
1270
+ self . day = aDecoder. decodeIntegerForKey ( " NS.day " )
1271
+ self . hour = aDecoder. decodeIntegerForKey ( " NS.hour " )
1272
+ self . minute = aDecoder. decodeIntegerForKey ( " NS.minute " )
1273
+ self . second = aDecoder. decodeIntegerForKey ( " NS.second " )
1274
+ self . nanosecond = aDecoder. decodeIntegerForKey ( " NS.nanosec " )
1275
+ self . weekOfYear = aDecoder. decodeIntegerForKey ( " NS.weekOfYear " )
1276
+ self . weekOfMonth = aDecoder. decodeIntegerForKey ( " NS.weekOfMonth " )
1277
+ self . yearForWeekOfYear = aDecoder. decodeIntegerForKey ( " NS.yearForWOY " )
1278
+ self . weekday = aDecoder. decodeIntegerForKey ( " NS.weekday " )
1279
+ self . weekdayOrdinal = aDecoder. decodeIntegerForKey ( " NS.weekdayOrdinal " )
1280
+ self . leapMonth = aDecoder. decodeBoolForKey ( " NS.leapMonth " )
1281
+ self . calendar = aDecoder. decodeObjectOfClass ( NSCalendar . self, forKey: " NS.calendar " )
1282
+ self . timeZone = aDecoder. decodeObjectOfClass ( NSTimeZone . self, forKey: " NS.timezone " )
1283
+ } else {
1284
+ NSUnimplemented ( )
1285
+ }
1219
1286
}
1220
1287
1221
1288
public func encodeWithCoder( aCoder: NSCoder ) {
1222
- NSUnimplemented ( )
1289
+ if aCoder. allowsKeyedCoding {
1290
+ aCoder. encodeInteger ( self . era, forKey: " NS.era " )
1291
+ aCoder. encodeInteger ( self . year, forKey: " NS.year " )
1292
+ aCoder. encodeInteger ( self . quarter, forKey: " NS.quarter " )
1293
+ aCoder. encodeInteger ( self . month, forKey: " NS.month " )
1294
+ aCoder. encodeInteger ( self . day, forKey: " NS.day " )
1295
+ aCoder. encodeInteger ( self . hour, forKey: " NS.hour " )
1296
+ aCoder. encodeInteger ( self . minute, forKey: " NS.minute " )
1297
+ aCoder. encodeInteger ( self . second, forKey: " NS.second " )
1298
+ aCoder. encodeInteger ( self . nanosecond, forKey: " NS.nanosec " )
1299
+ aCoder. encodeInteger ( self . weekOfYear, forKey: " NS.weekOfYear " )
1300
+ aCoder. encodeInteger ( self . weekOfMonth, forKey: " NS.weekOfMonth " )
1301
+ aCoder. encodeInteger ( self . yearForWeekOfYear, forKey: " NS.yearForWOY " )
1302
+ aCoder. encodeInteger ( self . weekday, forKey: " NS.weekday " )
1303
+ aCoder. encodeInteger ( self . weekdayOrdinal, forKey: " NS.weekdayOrdinal " )
1304
+ aCoder. encodeBool ( self . leapMonth, forKey: " NS.leapMonth " )
1305
+ aCoder. encodeObject ( self . calendar, forKey: " NS.calendar " )
1306
+ aCoder. encodeObject ( self . timeZone, forKey: " NS.timezone " )
1307
+ } else {
1308
+ NSUnimplemented ( )
1309
+ }
1223
1310
}
1224
1311
1225
1312
static public func supportsSecureCoding( ) -> Bool {
0 commit comments