[swift-users] dealing with heterogenous lists/dictionary with Codable

Itai Ferber iferber at apple.com
Thu Oct 19 15:13:33 CDT 2017


Even then, that wouldn’t necessarily help in the general case. If you 
decode `{"key" : 1}` as `[String : Codable]`, what concrete type would 
`1` have? `Int`? `Double`? `Int8`? (Arguments can be made for any one of 
these, but the key here is that it is inherently ambiguous and there 
isn’t necessarily a good answer.)

On 19 Oct 2017, at 12:57, David Sweeris wrote:

>> On Oct 19, 2017, at 12:50 PM, David Baraff via swift-users 
>> <swift-users at swift.org> wrote:
>>
>> Yes; this is a case where anywhere in the code base I want to just 
>> say
>> 	struct MyNewType : Codable {
>> 		// add codable datatypes
>> 	}
>>
>> and don’t want/can’t always go to the centralized place to add it 
>> in.
>> Is there some extension-like trick I can pull off that lets me spread 
>> the implementation out over different files/libraries?
>
> Ah, ok.
>
> No, I don't think you'll be able to do that until/unless Swift gets 
> more macro/metaprogramming features. Maybe if protocols ever get to 
> conform to themselves? That's a common request, but implementing it is 
> apparently beyond tricky. I'm pretty sure somebody's working on it, 
> but "bigger fish" and all that...
>
> - Dave Sweeris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20171019/1b49368f/attachment.html>


More information about the swift-users mailing list