Skip to content

carlynorama/CoderExplorer

Repository files navigation

Coder Explorer

A place to finally learn about custom encoders and decoders.

References

To work on this package I primarily used 3 resources, duplicating them line by line. No copy-paste. Xcode does a ton of providing missing code to be in compliance so that was less tedious than one may think. Some of the variable names will be changed from the example code. This is on purpose to make sure I don't start copy pasting and that I really do under stand what is connected to what.

Future Codable Directions

StackOverflow 45169254

Paulo Mattos provided an epic answer.

  • StringsCoder/KeyValueEncoder.swift

  • Tests: StringsCoderTests.swift

  • Strings

objc.io

Very good video on making a router coder from an enum.

  • objcCoder/RouterExample.swift
  • Tests:RouterExampleTests.swift

JSONEncoder

5.10

FoundationEssentials Version & Darwin/Foundation-swiftoverlay Version

Evolution Talk

A beast, but very instructive. Started from line 226 of the one in 5.10 and worked my way out until it worked.

    open func encode<T: Encodable>(_ value: T) throws -> Data {
        let value: JSONValue = try encodeAsJSONValue(value)
        let writer = JSONValue.Writer(options: self.outputFormatting)
        let bytes = writer.writeValue(value)

        return Data(bytes)
    }

That got ripped apart and turned into the first LineCoder. Then I found the one in FoundationEssentials and liked the way it had been reworked so tore everything out again.

Other Apple Encoders on GitHub

More To Read

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages