Can I use an NSPredicate in Swift with a nil argument?

后端 未结 2 853
再見小時候
再見小時候 2020-12-20 11:13

I\'m trying to convert a project that uses Core Data from Objective-C to Swift.

The data model is structured so that I have one master folder which contains other fo

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-20 11:44

    It looks as if it is (with the current Xcode 6 beta 3 release) generally difficult to pass nil in a variable argument list.

    This seems to work:

    let predicate = NSPredicate(format: "parentFolder == %@", 0)
    print(predicate)
    // Output: parentFolder == nil
    

    But the easiest solution would be to simply write the predicate as

    NSPredicate(format: "parentFolder == nil")
    

提交回复
热议问题