Snippets Collections
extension Encodable {
    func toDictionary() -> [String: Any]? {
        do {
            let encoder = JSONEncoder()
            let data = try encoder.encode(self)
            let dictionary = try JSONSerialization.jsonObject(with: data, options: .allowFragments) as? [String: Any]
            return dictionary
        } catch {
            print("Error converting to dictionary:", error)
            return nil
        }
    }
}
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)
         }
    }
}
import Foundation

class NotificationModel {
    
    var body = ""
    var senderId = ""
    var receiverId = ""
    var notificationId = ""
    var serviceProviderId = ""
    var timestamp = 0
    var title = ""
    var date = ""
    
    init(notification : [String:Any]) {
        
        self.body = notification["body"] as? String ?? ""
        self.senderId = notification["senderId"] as? String ?? ""
        self.receiverId = notification["receiverId"] as? String ?? ""
        self.notificationId = notification["notificationId"] as? String ?? ""
        self.serviceProviderId = notification["serviceProviderId"] as? String ?? ""
        self.title = notification["title"] as? String ?? ""
        self.date = notification["date"] as? String ?? ""
        self.timestamp = notification["timestamp"] as? Int ?? 0
    }
}
Make sure to add encodable like this 

struct modelName : Encodsble

let categories = categoriesArray.map{ $0.toDictionary()  }

extension Encodable {
    func toDictionary() -> [String: Any] {
        let mirror = Mirror(reflecting: self)
        var dictionary = [String: Any]()
        for child in mirror.children {
            guard let label = child.label else {
                continue
            }
            dictionary[label] = child.value
        }
        return dictionary
    }
}
struct Person : Encodable {
    var name: String
    var age: Int
    var address: String?
}
    
    
let person = Person(name: "John Smith", age: 30, address: nil)
let dictionary = person.toDictionary()
print(dictionary) // Output: ["name": "John Smith", "age": 30]
    
    
    extension Encodable {
    func toDictionary() -> [String: Any]? {
        let mirror = Mirror(reflecting: self)
        var dictionary = [String: Any]()
        for child in mirror.children {
            guard let label = child.label else {
                continue
            }
            dictionary[label] = child.value
        }
        return dictionary
    }
}
from torchsummary import summary
summ = summary(model, torch.Size((1,28,28)))
$this->load->library("form_validation");
$this->form_validation->set_rules("username", "User name", "trim|required");
if($this->form_validation->run() === FALSE)
{
     //$this->view_data["errors"] = validation_errors();
}
else
{
     //codes to run on success validation here
}
$sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";
$this->db->query($sql, array(3, 'live', 'Rick')); // insert in ci
star

Sat Jan 20 2024 02:11:01 GMT+0000 (Coordinated Universal Time) https://github.com/LaravelDaily/laravel-tips/blob/master/db-models-and-eloquent.md

#laravel #database #eloquent #model
star

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

#ios #swift #model #comment #comments
star

Fri Jul 07 2023 10:15:32 GMT+0000 (Coordinated Universal Time)

#ios #swift #notification #model
star

Fri Jun 23 2023 08:10:31 GMT+0000 (Coordinated Universal Time)

#ios #swift #dic #dict #model #modelarray #dictonary
star

Fri Mar 31 2023 06:42:39 GMT+0000 (Coordinated Universal Time)

#ios #swift #dict #model #dictionary
star

Tue Nov 29 2022 23:22:32 GMT+0000 (Coordinated Universal Time)

#pytorch #summary #model
star

Thu Feb 24 2022 13:43:32 GMT+0000 (Coordinated Universal Time)

#php #codeigniter #database #model
star

Thu Feb 24 2022 09:08:59 GMT+0000 (Coordinated Universal Time)

#php #codeigniter #database #model
star

Thu Feb 24 2022 08:48:16 GMT+0000 (Coordinated Universal Time) https://codeigniter.com/userguide3/database/query_builder.html

#php #codeigniter #database #model

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension