Avatar
あと夕方の @omochimetaru さんのやつは、こういうんじゃ嫌なんですか? struct FileURL: Codable { let url: URL init(from decoder: Decoder) throws { let container = try decoder.singleValueContainer() let path = try container.decode(String.self) guard path.first == "/" else { throw DecodingError.dataCorruptedError(in: container, debugDescription: "絶対パスにすること") } url = URL(fileURLWithPath: path) } func encode(to encoder: Encoder) throws { var container = encoder.singleValueContainer() try container.encode(url.path) } } struct Config : Codable { var a: FileURL } let decoder = JSONDecoder.init() let config = try decoder.decode(Config.self, from: json.data(using: .utf8)!) print(config.a.url.path) print(config.a.url.isFileURL)