comments Model (model in model)

PHOTO EMBED

Thu Aug 10 2023 05:53:22 GMT+0000 (Coordinated Universal Time)

Saved by @hasnat #ios #swift #model #comment #comments

import Foundation

struct CommentsModel {
    
  var comment = ""
  var gameId = ""
  var timestamp = 0
  var userId = ""
  var userModel = UserModel(user: [:])
    
    init(comment: [String: Any]) {
        
        self.comment = comment["comment"] as? String ?? ""
        self.gameId = comment["gameId"] as? String ?? ""
        self.timestamp = comment["timestamp"] as? Int ?? 0
        self.userId = comment["userId"] as? String ?? ""
        
        if let userDict = comment["userModel"] as? [String: Any] {
            self.userModel = UserModel(user: userDict)
         }
    }
}
content_copyCOPY