Skip to content

Instantly share code, notes, and snippets.

@MP0w
Last active January 13, 2017 10:56
Show Gist options
  • Save MP0w/55056abd76d526ed231b598b5c959e89 to your computer and use it in GitHub Desktop.
Save MP0w/55056abd76d526ed231b598b5c959e89 to your computer and use it in GitHub Desktop.
Dummy
import Foundation
/// Creates a Test dummy of the needed type!
/// Works with any value type or class (?)
func dummy<T>() -> T {
let size = MemoryLayout<T>.size
let alignment = MemoryLayout<T>.alignment
let p = UnsafeMutableRawPointer.allocate(bytes: size, alignedTo: alignment)
return p.bindMemory(to: T.self, capacity: 1).pointee
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment