magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.8k stars 1.79k forks source link

MR_findFirst _Nonnull? #1102

Closed emrsn-SebastianVancea closed 8 years ago

emrsn-SebastianVancea commented 8 years ago

Under Xcode 7 after calling MR_findFirstWithPredicate I can no longer check if the object is nil (i.e. no object found) because I get a build error: "Binary operator '==' cannot be applied to operands of type 'NSManagedObject' and 'NilLiteralConvertible'.

Is this the intended behaviour? Should I just replace every MR_findFirstWithPredicate with MR_findAllWithPredicate and check count? I feel like then it would defeat the purpose of the method.

hardikdevios commented 8 years ago

the New way to do this is very simple

let object:Entity_name? = Entity_name.MR_findFirst()

if object == nil {
  //Do your work here
} 
emrsn-SebastianVancea commented 8 years ago

Thank you

tonyarnold commented 8 years ago

Alternately, you can use the recommended if let syntax:

if let object = Entity_name.MR_findFirst() as? Entity_name {
    // Do your work here
}

You might be able to get away without the as? Entity_name — I haven't used MR with Swift much.

hardikdevios commented 8 years ago

@tonyarnold i have Already developed 2 Apps with Magical Records using swift and my friend lib is very smoothe and awesome even the foundation is not purely swift but it also doesnt have any performance issue with Objective-C and Swift bridging so for me All tests past :+1: for swift i hope we might seen Native Swift version of MR .