Skip to content

A Swift example on how to encode and decode objects in a class hierarcy

Notifications You must be signed in to change notification settings

anttijuu/ClassHierarchyCodableSample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ClassHierarchyCodable

A simple example on how to create a Swift class hierarcy and then enable encoding and decoding objects from and to JSON.

The example is based on the implementation from: https://nefkens.net/swift-json-encoding-decoding-and-subclasses/

The domain is a chat app/server, where there is a common base class Message. Subclasses include, for example, ChatMessage, ErrorMessage and StatusMessage. These have some common properties, overridden by subclasses if/when necessary.

See main.swift for a simple example on how to encode and decode between JSON and objects.

MessageHandler does the actual encoding and decoding.

Who did this

  • Antti Juustila
  • (c) Antti Juustila, 2023
  • MIT Licence

About

A Swift example on how to encode and decode objects in a class hierarcy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages