Skip to content

Instantly share code, notes, and snippets.

@jayz5
Last active September 24, 2018 02:51
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 jayz5/d70853cbf7d8b2ace461eddf7f33643c to your computer and use it in GitHub Desktop.
Save jayz5/d70853cbf7d8b2ace461eddf7f33643c to your computer and use it in GitHub Desktop.
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