title: Swift + Realm newbie: Problems with a simple Realm object and its initializers
body: <p>I've been a long time Objective-C developer and heard about Realm some weeks ago. On the other hand I've always wanted to migrate little by little to Swift, so I created a small project involving Realm + Swift.</p>
  
  <p>What does it mean? I'm a Swift + Realm newbie.</p>
  
  <p>Anyway, I created a small demo/Proof of concept for a project I have in mind and I thought it had to be easier. But Xcode compiler says otherwise.</p>
  
  <p>My problem is with one of my Objects' initializer(s).</p>
  
  <p>My intentions were simple, but apparently Realm needs more initializers than I wanted.</p>
  
  <p>The code of one of my Realm Objects is this:</p>
  
  <pre><code>import Foundation
  
  import Realm
  import RealmSwift
  
  class Partida: Object
  {
      dynamic var id_partida: String
      dynamic var inventario: Inventory?
  
      required init ()
      {
          inventario = Inventory()
          id_partida = "id_partida_test"
          super.init()
      }
  
  
  
      required init(value: AnyObject, schema: RLMSchema) {
          //fatalError("init(value:schema:) has not been implemented")
          super.init(value: value, schema: schema)
      }
  
  
      required init(realm: RLMRealm, schema: RLMObjectSchema) {
          //fatalError("init(realm:schema:) has not been implemented")
          super.init(realm: realm, schema: schema)
      }
  
      override class func primaryKey() -&gt; String? {
          return "id_partida"
      }
  
  }
  </code></pre>
  
  <p>My original code only had the "normal" init initializer. But Xcode forced me to create two additional initializers more (value and realm ones).</p>
  
  <p>If I compile the code I've just pasted above, Xcode complains in the 2nd and 3rd required initializers, specifically in the super.init part.
  It says:</p>
  
  <pre><code>Property 'self.id_partida' not initialized at super.init call
  </code></pre>
  
  <p>I understand the meaning of it, but I don't know how to avoid the error because if I remove both super.init lines, the program crashes in runtime.</p>
  
  <p>if I uncomment the fatalError lines, they also crashes in runtime.</p>
  
  <p>In fact I don't want to use these 2 initializers. If I could, I wouldn't add them, but Xcode needs to, apparently. The only code I really want to add to my object init function is "the simple" init function, which was the only part of code considered mine.</p>
  
  <p>I think I might have some concept misunderstandings in Realm + Swift + initializers.</p>
  
  <p>I'm also having the feeling Xcode is forcing me to add code I don't need and/or I don't understand either.</p>
  
  <p>Any help on understanding "required init" initializers in Realm will be more than welcome.</p>
  
  <p>Official Realm + Swift documentation is beyond my knowledge as I don't understand many of its concepts even after re-reading them many times.</p>
  
  <p>Google and StackOverflow haven't been really helpful this time...</p>
  
  <p>Thanks.</p>