Skip to content

Predicate to NSPredicate conversion fails (not tagged as ObjC) #36

Open
@helje5

Description

@helje5

Follow up to #22 by @HealsCodes:

I've been playing around with Predicates + ManagedModels but always run into a dead-end seemingly because Model properties aren't exposed to the underlying Objective-C runtime so code like this doesn't work:

@Model
final class MyModel: NSManagedObject {
  var enabled: Bool

  convenience init() {
    self.enabled = false
  }
}

// the following works if MyModel is created using the traditional NSManagedObject / @NSManaged means

let p = #Predicate<MyModel> { $0.enabled == true } 
let predicate = NSPredicate(p) // returns nil, because apparently MyModel.enabled isn't bridged

Likewise a simple NSExpression(forKeyPath: \MyModel.enabled) fails with "Foundation/NSObject.swift:132: Fatal error: Could not extract a String from KeyPath \MyModel.enabled"

The same issue breaks interoperability with packages like PredicateKit which relies on being able to convert AnyKeyPath to String using ObjC bridging internals.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions