title: iOS 8 Swift NSFetchResult predicate with Core Data relationship can't access internal ID
body: <p>Very new to Core Data but I've read that I can fetch data that uses Entity relationships. Now, coming from Mysql maybe I'm making too many assumptions, but I have 2 Entities set up with a Relationship between them and I can't fetch the proper data. </p>
  
  <p>Here are my 2 models:</p>
  
  <pre><code>@objc(Categories)
  class Categories: NSManagedObject {
      @NSManaged var category: String
      @NSManaged var exp: String
      @NSManaged var order: NSNumber
  }
  
  @objc(Techniques)
  class Techniques: NSManagedObject {
      @NSManaged var korean: String
      @NSManaged var order: NSNumber
      @NSManaged var spanish: String
      @NSManaged var categories: Categories
  }
  </code></pre>
  
  <p>After I created a Relationship from Techniques to Categories, Core Data added this field to the Sqlite DB:</p>
  
  <pre><code>ZCATEGORIES - INTEGER
  </code></pre>
  
  <p>Let's say I want to fetch all Techniques that belong to the category #3 (with internal ZID: 3)</p>
  
  <p>If I do this:</p>
  
  <pre><code>request.predicate = NSPredicate(format: "categories == %@", 3)
  </code></pre>
  
  <p>It works. But if I do:</p>
  
  <pre><code>request.predicate = NSPredicate(format: "categories == %@", category.category)
  </code></pre>
  
  <p>It doesn't work. I understand that it doesn't work because <code>category.category</code> is a String, not an Integer. </p>
  
  <p>My question is:</p>
  
  <p>Do I have to create my own relationhip IDs field in the Category Entity and set that, then reference the Technique like:</p>
  
  <pre><code>request.predicate = NSPredicate(format: "categories == %@", category.categoryID)
  </code></pre>
  
  <p>?</p>
  
  <p>Isn't there a way to access the Category's internal ID to get this relationship to work? </p>
  
  <p>Or better yet, it would seem to me that there should be an internal mechanish to retrieve these relationships without writing a SQL-like query but just using the Object, something like: <code>Techniques.categores</code>.</p>
  
  <p>Thanks. I haven't found a good answer anywhere. </p>