title: how to make realm CRUD operation in separate swift file?
body: <p>I am a beginner in iOS development and in programming, I am trying to make a swift file that contain realm CRUD operation called <code>RealmService</code> , so I don't have to write do catch block and try! realm all over the place, like my code below</p>
  
  <pre><code>import Foundation
  import RealmSwift
  
  class RealmService {
  
      var realm = try! Realm()
  
      func save(_ object: Object) {
          do {
              try realm.write {
                  realm.add(object)
              }
          } catch {
              print("Failed to save \(object) in realm: \(error.localizedDescription)")
          }
      }
  
      func load(_ object: Object) -&gt; Results&lt;Object&gt;? {
          return realm.objects(object.self)
      }
  
      func update(_ object: Object, with dictionary: [String: Any?]) {
          do {
              try realm.write {
                  for (key, value) in dictionary {
                      object.setValue(value, forKey: key)
                  }
              }
          } catch {
              print("Failed to update \(object) in realm: \(error.localizedDescription)")
          }
      }
  
      func delete(_ object: Object) {
          do {
              try realm.write {
                  realm.delete(object)
              }
          } catch {
              print("Failed to delete \(object) in realm: \(error.localizedDescription)")
          }
      }
  }
  </code></pre>
  
  <p>but in the <code>load</code> method, I get an error in the line <code>realm.objects(object.self)</code> , it is said</p>
  
  <blockquote>
    <p>Cannot convert value of type 'Object' to expected argument type
    'Object.Type'</p>
  </blockquote>
  
  <p><a href="https://i.stack.imgur.com/J81Ta.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/J81Ta.png" alt="enter image description here"></a></p>
  
  <p>I think I make mistake when insert object.self in the realm.objects. it should be element.type, but I dont have a clue what is this element type like this picture
  <a href="https://i.stack.imgur.com/TVIs6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TVIs6.png" alt="enter image description here"></a></p>
  
  <p>how to load data from realm? sadly i just know a little bit from youtube tutorial by using  <code>realm.objects(object.self)</code></p>