Swift의 Codable을 사용하여 사전으로 인코딩하려면 어떻게해야합니까? Swift 4를 구현하는 구조체가 Codable있습니다. 해당 구조체를 사전으로 인코딩하는 간단한 기본 제공 방법이 있습니까? let struct = Foo(a: 1, b: 2) let dict = something(struct) // now dict is ["a": 1, "b": 2] 약간의 데이터 이동에 신경 쓰지 않는다면 다음과 같이 사용할 수 있습니다. extension Encodable { func asDictionary() throws -> [String: Any] { let data = try JSONEncoder().encode(self) guard let dictionary = try JSONSerializati..