title: Core Data: Extend Predicate to fetch related entities with special Attribute-Value
body: <p>I've got 2 entities (1 to many), both with a boolean flag "visible"</p>
  
  <p>To fetch all visible Entities of A i use</p>
  
  <pre><code>request.predicate = NSPredicate(format:"visible != false")
  </code></pre>
  
  <p>This way I get all visible A filled with all B (including the non visible)</p>
  
  <p><strong>Question</strong>: Is it possible to extend the predicate to fetch all visible A filled only with all visible Entities of B?
  Or do I have to loop through all Entities?</p>
  
  <p>Thanks!</p>
  
  <p><strong>[Update 1]</strong> Here is some code:</p>
  
  <pre><code>class A: NSManagedObject {
      @NSManaged var visible: NSNumber
      @NSManaged var relationShipToB: NSSet
  }
  class B: NSManagedObject {
      @NSManaged var visible: NSNumber
      @NSManaged var relationShipToA: NSManagedObject
  }
  </code></pre>
  
  <p><strong>[Update 2]</strong> This is how my workaround looks like (in Swift)</p>
  
  <pre><code>class A: NSManagedObject {
      @NSManaged var visible: NSNumber
      @NSManaged var relationShipToB: NSSet
      var visibleB:[B] {
          get {
              var result = [B]()
              for b in relationShipToB.allObjects as [B] {
                  if(b.visible.boolValue) {
                      result.append(b)
                  }
              }
              return result
          }
      }
  }
  </code></pre>
  
  <p><strong>[Update 3]</strong>
  Lets say we have following instances:</p>
  
  <pre><code>A1 {
      visible = "true"
      toB = [B1, B2]
  }
  
  A2 {
      visible = "true"
      toB = [B3]
  }
  
  B1 {
      visible = "true"
  }
  
  B2 {
      visible = "false"
  }
  
  B3 {
      visible = "false"
  }
  </code></pre>
  
  <p>Expected result:</p>
  
  <pre><code>A1 [B1]
  A2 []
  </code></pre>
  
  <p>As the result of my request I want to get <em>A1</em> and <em>A2</em> (both are visible).
  But as an containing <em>A1.toB</em> I <strong>only</strong> want to have <em>B1</em> (<em>B2</em> is not visible)
  And <em>A2.toB</em> will be emty, because <em>B3</em> is not visible.</p>