Most useful persistence mechanism to store a tree in Swift

I have a tree data structure to represent a chess game or rather a chess repertoire. A tree starts with a root and subsequent moves which all describe a given board position. A position can be serialized as a string(FEN notation). A move can be byte encoded or as a string detailing the source and destination square. There can be multiple moves in a given position meaning there is more than one variation on how to continue.

Given one or more repertoires (read trees) I want to be able to train these repertoires via spaced repetition. So i need to persist whether a user has correctly guessed the next move or not. If a user does not review already learned moves but learns new ones I want to distinguish between several algorithms to determine which move to learn next (depth first, breadth-over-depth).

Therefore I want to be able to load these trees from some kind of persistence layer and save progress information back to the disk.

I found I have several options, each coming with a drawback and I would like your opinion whether I missed something obvious or which options you would prefer and why.

  1. Store as json/plist on disk
  2. Store via CoreData
  3. Store via SwiftData
  4. Store via SQLite db

Regarding the first option I love the simplicity of it but am thinking I will have a hard time implementing syncing down the road. Ultimately the training progress and repertoires should be synched to all your devices.

SwiftData seems to have poor performance with large data sets as far as I read and I can see a scenario where I will store a lot of data.

SQLite would be my preferred solution but I am not quite sure whether a relational schema is a good fit for my needs. Maybe I could use a json field in this db to get some benefits of option 1?

Leaves me with CoreData which seems to be the way to go atm.

I am wondering how you would tackle this problem and what your thoughts are on this. One particular problem I struggle with is that I want to maintain the variations of a given repertoire, meaning I want to be able to recreate the unique variation lines of a repertoire. Otherwise I could just save a moves table with all unique positions and its continuations and be done with it. What I came up with for a sqlite schema is this, but again I would love some thoughts on this.

Model:

/// GameNode represents a node of a chess game tree
public final class GameNode: CustomStringConvertible {
    
    // MARK: - Properties
    
    /// The position of the node
    public let position: Position
    
    /// Uniquely identifies a node
    public let nodeId: UUID
    
    /// Is the node at the top of the tree
    public let isTopNode: Bool
    
    /// The chess move that gets from the parent node to this one
    public let move: Move?
    
    /// An optional move annotation like !!, !?, ??
    public internal(set) var annotation: String?
    
    /// A comment before the move
    public internal(set) var startingComment: String?
    
    /// A comment after the move
    public internal(set) var comment: String?
    
    /// The parent node
    /// This is a weak property to avoid a potential retain cycle
    public internal(set) weak var parent: GameNode?
    
    /// Possible variations from this node
    /// To avoid potential retain cycles do not add self
    /// or a parent node to the array
    /// Node at first index is considered the main continuation
    public internal(set) var variations: [GameNode]
}

Schema:

-- Create Repertoire table
CREATE TABLE Repertoire (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    pgn TEXT NOT NULL,
    name TEXT NOT NULL,
    UNIQUE(pgn, name)
);

-- Create Variant table
CREATE TABLE Variant (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT NOT NULL,
    repertoireId INTEGER NOT NULL,
    FOREIGN KEY(repertoireId) REFERENCES Repertoire(id)
);

-- Create Move table
CREATE TABLE Move (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    dueDate INTEGER,
    easeFactor REAL,
    numberOfSuccessfulReviewsInARow INTEGER,
    fenBefore TEXT NOT NULL,
    fenAfter TEXT NOT NULL,
    san TEXT NOT NULL,
    variantId INTEGER NOT NULL,
    ply INTEGER NOT NULL,
    FOREIGN KEY(variantId) REFERENCES Variant(id),
    UNIQUE(fenBefore, san, ply, variantId)
);

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật