@@ -286,16 +286,18 @@ open class NSAffineTransform : NSObject, NSCopying, NSSecureCoding {
286
286
preconditionFailure ( " Unkeyed coding is unsupported. " )
287
287
}
288
288
289
- let pointer = UnsafePointer < Float > ( [
289
+ let array = [
290
290
Float ( transformStruct. m11) ,
291
291
Float ( transformStruct. m12) ,
292
292
Float ( transformStruct. m21) ,
293
293
Float ( transformStruct. m22) ,
294
294
Float ( transformStruct. tX) ,
295
295
Float ( transformStruct. tY) ,
296
- ] )
297
-
298
- aCoder. encodeArray ( ofObjCType: " [f] " , count: 6 , at: pointer)
296
+ ]
297
+
298
+ array. withUnsafeBytes { pointer in
299
+ aCoder. encodeValue ( ofObjCType: " [6f] " , at: UnsafeRawPointer ( pointer. baseAddress!) )
300
+ }
299
301
}
300
302
301
303
open func copy( with zone: NSZone ? = nil ) -> Any {
@@ -312,20 +314,20 @@ open class NSAffineTransform : NSObject, NSCopying, NSSecureCoding {
312
314
preconditionFailure ( " Unkeyed coding is unsupported. " )
313
315
}
314
316
315
- let pointer = UnsafeMutablePointer < Float > . allocate( capacity : 6 )
317
+ let pointer = UnsafeMutableRawPointer . allocate ( bytes : MemoryLayout < Float > . stride * 6 , alignedTo : 1 )
316
318
defer {
317
- pointer. deinitialize ( )
318
- pointer. deallocate ( capacity: 6 )
319
+ pointer. deallocate ( bytes: MemoryLayout < Float > . stride * 6 , alignedTo: 1 )
319
320
}
320
- aDecoder. decodeArray ( ofObjCType: " [f] " , count: 6 , at: pointer)
321
-
322
- let m11 = pointer [ 0 ]
323
- let m12 = pointer [ 1 ]
324
- let m21 = pointer [ 2 ]
325
- let m22 = pointer [ 3 ]
326
- let tX = pointer [ 4 ]
327
- let tY = pointer [ 5 ]
321
+ aDecoder. decodeValue ( ofObjCType: " [6f] " , at: pointer)
328
322
323
+ let floatPointer = pointer. bindMemory ( to: Float . self, capacity: 6 )
324
+ let m11 = floatPointer [ 0 ]
325
+ let m12 = floatPointer [ 1 ]
326
+ let m21 = floatPointer [ 2 ]
327
+ let m22 = floatPointer [ 3 ]
328
+ let tX = floatPointer [ 4 ]
329
+ let tY = floatPointer [ 5 ]
330
+
329
331
self . transformStruct = AffineTransform ( m11: CGFloat ( m11) , m12: CGFloat ( m12) ,
330
332
m21: CGFloat ( m21) , m22: CGFloat ( m22) ,
331
333
tX: CGFloat ( tX) , tY: CGFloat ( tY) )
0 commit comments