Last active
September 30, 2019 16:10
-
-
Save CH3COOH/c17a03b60eef4f2042816fd0fd65c027 to your computer and use it in GitHub Desktop.
LicensePlist がiOS 13.1.1でクラッシュする問題
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
import Foundation | |
import LoggerAPI | |
struct LicensePlistHolder { | |
let root: Data | |
let items: [(LicenseInfo, Data)] | |
static func load(licenses: [LicenseInfo], options: Options) -> LicensePlistHolder { | |
var rootItems: [[String: String]] = licenses.map { license in | |
return ["Type": "PSChildPaneSpecifier", | |
"Title": license.name(withVersion: options.config.addVersionNumbers), | |
"File": "\(options.prefix)/\(license.name)"] | |
} | |
rootItems.insert(["Type": "PSGroupSpecifier", "Title": "Licenses"], at: 0) | |
let root = try! PropertyListSerialization.data(fromPropertyList: ["PreferenceSpecifiers": rootItems], | |
format: .xml, | |
options: 0) | |
let items: [(LicenseInfo, Data)] = licenses.map { license in | |
let item = ["PreferenceSpecifiers": [["Type": "PSGroupSpecifier", "FooterText": license.body]]] | |
let value = try! PropertyListSerialization.data(fromPropertyList: item, format: .xml, options: 0) | |
return (license, value) | |
} | |
return LicensePlistHolder(root: root, items: items) | |
} | |
func deserialized() -> (root: [String: [[String: String]]], items: [(LicenseInfo, [String: [[String: String]]])]) { | |
let root = try! PropertyListSerialization.propertyList(from: self.root, options: [], format: nil) as! [String: [[String: String]]] | |
let items: [(LicenseInfo, [String: [[String: String]]])] = self.items.map { license, data in | |
let value = try! PropertyListSerialization.propertyList(from: data, options: [], format: nil) as! [String: [[String: String]]] | |
return (license, value) | |
} | |
return (root: root, items: items) | |
} | |
func write(to rootPath: URL, itemsPath: URL) { | |
do { | |
try root.write(to: rootPath) | |
try items.forEach { | |
try $0.1.write(to: itemsPath.appendingPathComponent("\($0.0.name).plist")) | |
} | |
} catch let e { | |
Log.error("Failed to write to (rootPath: \(rootPath), itemsPath: \(itemsPath)).\nerror: \(e)") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment