This repository has been archived by the owner on Sep 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from num42/feature/code_optimisation
Feature/code optimisation
- Loading branch information
Showing
13 changed files
with
345 additions
and
140 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import CoreImage | ||
|
||
struct AppIconEntry: Encodable, Hashable { | ||
let size: CGFloat | ||
let idiom: String | ||
let scale: Int | ||
|
||
var scaledSize: CGFloat { | ||
return size * CGFloat(scale) | ||
} | ||
|
||
var fileName: String { | ||
return "AppIcon-\(Int(scaledSize))x\(Int(scaledSize)).png" | ||
} | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case size | ||
case idiom | ||
case fileName = "filename" | ||
case scale | ||
} | ||
|
||
private var displaySize: String { | ||
return Double(size).withDecimals(1).replacingOccurrences(of: ".0", with: "") | ||
} | ||
|
||
func encode(to encoder: Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
try container.encode("\(displaySize)x\(displaySize)", forKey: .size) | ||
try container.encode("\(scale)x", forKey: .scale) | ||
try container.encode(idiom, forKey: .idiom) | ||
try container.encode(fileName, forKey: .fileName) | ||
} | ||
} | ||
|
||
struct AppIconSetContents: Encodable { | ||
let iconEntries: [AppIconEntry]? | ||
let info: Info | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case iconEntries = "images" | ||
case info | ||
} | ||
} | ||
|
||
struct Info: Encodable { | ||
let version: Int | ||
let author: String | ||
} | ||
|
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
Oops, something went wrong.