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 folders - and those folders can also contain other folders, via a "parentFolder" relationship.
Currently, I do this in Objective-C to retrieve the master folder (it finds the only folder without a "parentFolder", and works as expected):
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:"Folder"];
request.predicate = [NSPredicate predicateWithFormat:@"parentFolder == %@", nil];
let request = NSFetchRequest(entityName: "Folder")
request.predicate = NSPredicate(format: "parentFolder == %@", nil)
It looks as if it is (with the current Xcode 6 beta 3 release) generally difficult
nil in a variable argument list.
This seems to work: (Update: This does not work with Swift 3 anymore.)
let predicate = NSPredicate(format: "parentFolder == %@", nil as COpaquePointer) println(predicate) // Output: parentFolder == nil
But the easiest solution would be to simply write the predicate as
NSPredicate(format: "parentFolder == nil")