Use yourData.count and divide it into 1024 * 1024. Using Alexanders is a great suggestion:
func stackOverflowAnswer() { if let data = UIImagePNGRepresentation(#imageLiteral(resourceName: "VanGogh.jpg")) as Data? { print("There were \(data.count) bytes") let bcf = ByteCountFormatter() bcf.allowedUnits = [.useMB]
With the following results:
There were 28865563 bytes formatted result: 28.9 MB
source share