Skip to content

Instantly share code, notes, and snippets.

@mackoj
Last active May 19, 2022 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mackoj/747f6258d678490379a8ff8abe92447a to your computer and use it in GitHub Desktop.
Save mackoj/747f6258d678490379a8ff8abe92447a to your computer and use it in GitHub Desktop.
Get size of a struct
import Foundation
/*
print("💾 AddCustomParamsState size: \(bytesFormater(bytes: MemoryLayout<AddCustomParamsState>.size))")
*/
public func bytesFormater(bytes: Int) -> String {
let bf = ByteCountFormatter()
bf.allowedUnits = .useBytes
bf.countStyle = .memory
bf.includesUnit = true
bf.isAdaptive = true
return bf.string(fromByteCount: Int64(bytes))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment