Advertisement
Guest User

Untitled

a guest
Apr 20th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. import Foundation
  2.  
  3. func test(count: Int) -> UInt8 {
  4. precondition(count >= 1)
  5.  
  6. let ptr = UnsafeMutableRawPointer.allocate(byteCount: count, alignment: 1)
  7. ptr.storeBytes(of: 0, toByteOffset: 0, as: UInt8.self)
  8.  
  9. let data = Data(bytesNoCopy: ptr, count: count, deallocator: .none)
  10. ptr.storeBytes(of: 13, toByteOffset: 0, as: UInt8.self)
  11. return data[0]
  12. }
  13.  
  14. for i in 1...24 {
  15. print("\(i): \(test(count: i))")
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement