Here is my code which actually working as I expect :
static func imageName(for page: Int, isThumbnail: Bool) -> String {
return isThumbnail ? "\(page)_thumb.jpg" : "\(page).jpg"
}
static func writeImageFile(with data: Data, issue: Issue, page: Int) throws -> URL {
let path = MediaFileManager.issueImagesDirectoryURL(issue: issue)
let imagePath = path.appendingPathComponent("\(imageName(for: page, isThumbnail: false))")
let thumbPath = path.appendingPathComponent("\(imageName(for: page, isThumbnail: true))")
try data.write(to: imagePath)
try data.write(to: thumbPath)
return path
}
I want the same result: - create 2 different constants which append to the main path - write 2 data to this 2 paths
Is that possible to refactor the writeImageFile()?
Aucun commentaire:
Enregistrer un commentaire