title: How to do Abstract Entities in Realm.io in Swift
body: <p>I am converting from CoreData to Realm.io I did a little experiment to see how Realm.io handles situations where I need to have subclasses of a class that is an RLMObject.</p>
  
  <p>Model</p>
  
  <pre><code>import Realm
  
  @objc enum RecurrenceEnum : Int {
      case Daily = 1
      case Weekly = 2
      case Monthly = 3
  }
  
  class Challenge: RLMObject {
      dynamic var title = ""
  }
  
  class TotalCountChallenge: Challenge {
      dynamic var totalCountGoal: Int = 0
  }
  
  class RecurringChallenge: Challenge {
      dynamic var recurranceType: RecurrenceEnum = .Daily
      dynamic var totalCountGoal: Int = 0
  }
  </code></pre>
  
  <p>When I save either a TotalCountChallenge or A RecurringChallenge it reports no errors but when I go to query for challenges by title I don't get anything back.</p>
  
  <p>Query from my ViewController</p>
  
  <pre><code>// Query using an NSPredicate object
  let predicate = NSPredicate(format: "title BEGINSWITH %@", "Booya")
  var challenges = Challenge.objectsWithPredicate(predicate)
  
  if challenges == nil || challenges.count == 0 {
      let tcChallenge = TotalCountChallenge()
      tcChallenge.title = "Booya Total Count Challenge"
      tcChallenge.totalCountGoal = 1_000_000
  
      let rChallenge = RecurringChallenge()
      rChallenge.title = "Booya Recurring Challenge"
      rChallenge.recurranceType = .Weekly
      rChallenge.totalCountGoal = 2_000_000
  
      let realm = RLMRealm.defaultRealm()
      // You only need to do this once (per thread)
  
      // Add to the Realm inside a transaction
      realm.beginWriteTransaction()
      realm.addObject(tcChallenge)
      realm.addObject(rChallenge)
      realm.commitWriteTransaction()
  }
  
  challenges = Challenge.objectsWithPredicate(predicate)
  if challenges != nil &amp;&amp; challenges.count &gt; 0 {
      for challenge in challenges {
          let c = challenge as! Challenge
          println("\(c.title)")
      }
  } else {
      println("No Challenges found")
  }
  
  challenges = TotalCountChallenge.objectsWithPredicate(predicate)
  if challenges != nil &amp;&amp; challenges.count &gt; 0 {
      for challenge in challenges {
          let c = challenge as! Challenge
          println("TotalCountChallenge: \(c.title)")
      }
  } else {
      println("No Total Count Challenges found")
  }
  
  challenges = RecurringChallenge.objectsWithPredicate(predicate)
  if challenges != nil &amp;&amp; challenges.count &gt; 0 {
      for challenge in challenges {
          let c = challenge as! Challenge
          println("RecurringChallenge \(c.title)")
      }
  } else {
      println("No Recurring Challenges found")
  }
  </code></pre>
  
  <p>Output</p>
  
  <pre><code>No Challenges found
  TotalCountChallenge: Booya Total Count Challenge
  RecurringChallenge Booya Recurring Challenge
  </code></pre>
  
  <p>When I look at the database using the Browse Tool provided by Realm I see that there is only 1 TotalCountChallenge and 1 RecurringChallenge and there are no Challenges</p>
  
  <p><img src="https://i.stack.imgur.com/Gr2Sd.png" alt="enter image description here"></p>
  
  <p>Is there a way to do this?</p>
  
  <p>Here is a link to the code in github: <a href="https://github.com/lewissk/RealmTest" rel="nofollow noreferrer">lewissk/RealmTest</a></p>