Last active
September 24, 2018 02:51
-
-
Save jayz5/d70853cbf7d8b2ace461eddf7f33643c to your computer and use it in GitHub Desktop.
This file contains 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
func checkFileSizesDemo() { | |
guard let docDir = FileManager.default.urls(for: .documentDirectory, | |
in: .userDomainMask).first else { | |
return | |
} | |
do { | |
let testDir = docDir.appendingPathComponent("test") | |
try FileManager.default.createDirectory(at: testDir, | |
withIntermediateDirectories: true, | |
attributes: nil) | |
let textURL = testDir.appendingPathComponent("text_size_test") | |
let text = """ | |
Let us always meet each other with smile, for the smile is the beginning of love. | |
Mother Teresa | |
""" | |
try text.write(to: textURL, atomically: true, encoding: .utf8) | |
if let image = UIImage(named: "swift-og") { | |
let pngURL = testDir.appendingPathComponent("png_size_test") | |
let pngData = image.pngData() | |
try pngData?.write(to: pngURL, options: [.atomic]) | |
let jpgURL = testDir.appendingPathComponent("jpg_size_test") | |
let jpgData = image.jpegData(compressionQuality: 1.0) | |
try jpgData?.write(to: jpgURL, options: [.atomic]) | |
} | |
FileManager.default.checkFileSizes(in: docDir) | |
} catch { | |
print("error: \(error)") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment