Created
January 6, 2025 21:02
-
-
Save SteveTrewick/0c3d0fb0eab403e965c74ebb9cf5f1a5 to your computer and use it in GitHub Desktop.
stored a metatype and need to get the MemoryLayout, etc? Yeah, me too.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // if we have a type param, can we get the bits we need out of it, | |
| // like length? | |
| let xtype = UInt16.self | |
| // MemoryLayout<xtype> etc, no no no, so ... | |
| func sizeof<T>(_ value: T.Type) -> Int { | |
| MemoryLayout<T>.size | |
| } | |
| let sz = sizeof(xtype) | |
| print(sz) // 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment