Skip to content
This repository has been archived by the owner on Feb 8, 2021. It is now read-only.

Swift 4 - Decodable/Encodable protocols #296

Closed
ferusinfo opened this issue Jun 6, 2017 · 21 comments
Closed

Swift 4 - Decodable/Encodable protocols #296

ferusinfo opened this issue Jun 6, 2017 · 21 comments
Labels

Comments

@ferusinfo
Copy link
Contributor

New Swift 4 will include a new encoding/decoding protocols (https://github.com/apple/swift-evolution/blob/master/proposals/0166-swift-archival-serialization.md)

Since Gloss is sharing the same namespace for protocols Decodable/Encodable, I suggest we change the name of the protocols, so Gloss can be a separate library to the new solution proposed by the Swift language team.

@hkellaway - thoughts?

@hkellaway
Copy link
Owner

hkellaway commented Jun 6, 2017

yeah - i saw that and was thinking similarly 😑 perhaps JSONDecodable and JSONEncodable.

i'll create a swift_4.0 branch for if you or any of the WWDCers feel inspired to get tinkering

@ejmartin504
Copy link
Contributor

Since Swift has module namespacing, for now Gloss is usable in XCode 9 by simply prepending "Gloss." to all use of Decodable and Encodable. Probably not an ideal solution long term though!

@ryanschneider
Copy link
Contributor

Have you considered making a Gloss 2.0 which builds on top of the Swift 4 primitives?

I haven't dug in deeply, but I feel like these spots can be much more ergonomically handled by a 3rd party library like Gloss than what's in Swift 4:

  • custom date encoding/decoding. Personally I have Glossy structs that have Date fields that need to use different DateFormatters (e.g. for legacy reasons some fields are UTC, some ISO8601, and others just MM/DD/YYYY). Swift.Codable requires me to set the encoder/decoders date decoding to custom, and then inspect the CodingKey keyPath to decide on the DateFormatter to use (since I can't use the same DateFormatter for all of the fields)

  • custom encode/decode functions: Personal choice, but I prefer Gloss' ~~> and <~~ to the try-heavy approach used in init(from decoder: Decoder) and func encode(to encoder: Encoder).

I feel like there's room for a "DSL" over Codable that combines the CodingKey concept (which is great!) with Gloss' ergonomics (which is even greater!).

Even a Gloss 1.x that adds support for CodingKeys for the JSON keys would be awesome (no more duplicating key name strings in toJSON and `init1!).

@hkellaway
Copy link
Owner

Neat ideas! Though I had not considered a re-write on top of Swift JSON parsing. I was simply going to update for compatibility. I was more viewing this an opportunity to eventually halt feature development as native JSON parsing gains popularity. I don't have the bandwidth to personally support Gloss indefinitely.

I agree there's room for a DSL on top of Swift's and others are free to take that notion and other ones present in Gloss and run with it.

@lastcc
Copy link

lastcc commented Jul 30, 2017

@hkellaway according to the doc, we have to write 2 separate methods to support transform and reverse transform, but ObjectMapper requires only one.

I know if we use 2 methods there are certain benefits, but can I only write one?
--------------------------------
If you use carthage the display names in the terminal output have some issues:
*** Building scheme "Gloss" in Gloss.xcodeproj
*** Building scheme "Gloss MacOS" in Gloss.xcodeproj

i think we can change it to be Gloss iOS and Gloss macOS

@hkellaway
Copy link
Owner

@lastcc im interpreting this as 2 separate questions

  1. im not familiar with ObjectMapper - taking a quick look at their docs, maybe you're talking about their TransformOf syntax? no, there is not an equivalent in Gloss
  2. true, the naming of the framework targets could be more precise as you describe

@ergunkocak
Copy link

Is it possible to start a new version string for swift 4 branch like 1.4.x and release on Cocoapods?
I know we can use with branch parameter in cocoapods but to be able to use in podspec file of my private pod i need a seperate version. AFAIS pod version is same in "swift_4.0" branch as "master"

@hkellaway
Copy link
Owner

@ergunkocak swift_4.0 is currently the same as master so you can point to 1.2.4 in your private spec. once updates for Swift 4.0 are made i can release specific betas on CocoaPods, sure

@ryanschneider
Copy link
Contributor

ryanschneider commented Sep 15, 2017 via email

@hkellaway
Copy link
Owner

thats good to know, tnx @ryanschneider

@hkellaway
Copy link
Owner

fyi - version 2.0.0-beta.1 has been released with minimum changes for Swift 4 compability

@GabrielAraujo
Copy link

@hkellaway do you need some help fully migrating to swift 4?

@hkellaway
Copy link
Owner

@GabrielAraujo i appreciate you asking - i could use assistance.

version 2.0.0-beta.1 should work with Swift 4. however, it would be nice to have uniquely named protocols to disambiguate from Foundation. i was thinking JSONDecodable and JSONEncodable.

are there other Swift 4 migration tasks you see?

@GabrielAraujo
Copy link

@hkellaway I would go with something gloss unique like GlossDecodable and GlossEncodable to avoid this happening again in the future. Hahah

I don't think so.. This is the only thing the compiler is complaining.

I think it would be great to release the swift 4.0 as the official so the projects that depend on gloss like moya-gloss can also be migrated! =)

@hkellaway
Copy link
Owner

@GabrielAraujo i think i still prefer JSONDecodable and JSONEncodable, more descriptive

if you'd like to help move to that, that'd be great

@GabrielAraujo
Copy link

GabrielAraujo commented Nov 4, 2017

@hkellaway I began to perform the changes to JSONDecodable and JSONEncodable but I also noticed that Encoder, Decoder, JSONEncoder and JSONDecoder are already being used by swift. Do you think we should also change the names for Encoder and Decoder or is it just too much? hahah
https://github.com/GabrielAraujo/Gloss

@hkellaway
Copy link
Owner

thanks @GabrielAraujo! im okay leaving those as-is

@GabrielAraujo
Copy link

@hkellaway
#311

@hkellaway
Copy link
Owner

naming will be updated to JSONDecodable and JSONEncodable as of version 2.0.0-beta.2

thanks @GabrielAraujo!

@GabrielAraujo
Copy link

@hkellaway glad to help!!

Man, is there any remaining changes in the roadmap? Why is it beta?

@hkellaway
Copy link
Owner

just giving folks time to report any issues with the Swift 4 version before the official release of 2.0

there is one outstanding PR submitted before Swift 4 transition I want to revisit

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants