Entities layers
Currently project has 3 layers of entities:
CoreData and Protobuf layer can be skipped for some entities, it depends on do we need to store entity in database and send/receive it through socket connection respectively.
Domain layer
These are structures that we use everywhere in project. There are mapped from/to entities of other layers.
CoreData
Layer for storing data in database.
Entities are described as NSManagedObject
subclasses. All these subclasses are created manually (CoreData's entity code generation is turned off for each entity). Each NSManagedObject
subclass name follows Managed<entity_name>
pattern (e. g. ManagedProfile
, ManagedMessage
, etc).
Data structure is described in *.xcdatamodel
file. Currenly we have only lightweight migrations for different app versions. Each version name follows ChatApp <app_version>.xcdatamodel
pattern (e. g. ChatApp 1.8.2.xcdatamodel
).
Mapping to/from domain layer entities is done via ManagedObjectConvertible
(domain entity -> CoreData entity) and ManagedObjectSerializable
(CoreData entity -> domain entity) protocols.
Protobuf
Protocol buffersopen in new window are Google's language-neutral, platform-neutral, extensible mechanism for serializing structured data. We use this format for transfering data via socket connection.
Messages.proto
file contains all the structures used in transfer. Think of it as a contract between each platform envolved in communication (currently these are iOS, Android and Backend). Messages.proto
file should be changed ONLY by agreement with all platforms.
To apply Protocol buffers to Swift application Swift Protobufopen in new window library is used. All structures from Messages.proto
file are converted to Messages.pb.swift
auto-generated file that contains Swift structures. More information on how to convert *.proto
files to *.swift
files can be found in Swift Protobuf Pluginopen in new window section of Swift Protobuf documentation. All generated Swift structure names follow Proto_<entity_name>
pattern (e. g. Proto_Event
, Proto_Message
, etc).
Mapping of generated Swift structures to/from domain layer entities is done via ProtocolBufferEquivalent
protocol.