Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
次のオブジェクトを検討してください。
struct User: Codable { let id: Int let email: String let name: String }
CodingKey特定の特定のものを取得することは可能KeyPathですか?
CodingKey
KeyPath
let key = \User.name.codingKey // would be equal to string: "name"
プロパティを直接文字列に変換できるとは思いませんが、リフレクションを使用して同様のことを実現できますが、構造体のインスタンスを作成する必要があります。
let user = User(id: 1, email: "sample@email.com", name: "just_name") Mirror(reflecting: user).children.first?.label