[swift-users] fileprivate extensions can't add protocol conformance

Matthew Johnson matthew at anandabits.com
Mon Feb 13 10:30:44 CST 2017


> On Feb 13, 2017, at 10:28 AM, Alejandro Martinez via swift-users <swift-users at swift.org> wrote:
> 
> Hi,
> 
> I found myself writting some method that parsed an API response and
> wanted to use Decodable to map the response into a struct declared
> elsewhere.
> My idea was that each api response handler file (I use completely
> different APIs that map into the same model) could add it's own
> fileprivate conformance to decodable into the model struct so each api
> response handler would use a different decoding function. But I found
> the compiler telling me that is not possible.
> 
> I can easily change my design, is not an issue but I'm super curious.
> Why fileprivate extensions can't add protocol conformance? Is there a
> technical reason behind? or a conscience design?

Extensions that add a protocol conformance are not allowed to have an access modifier applied because the conformance is currently required to have the same visibility as the protocol itself.

> 
> Thanks!
> 
> 
> -- 
> Alejandro Martinez
> http://alejandromp.com
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users



More information about the swift-users mailing list