Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 如何使用NSPredicate返回true?_Swift_Nspredicate - Fatal编程技术网

Swift 如何使用NSPredicate返回true?

Swift 如何使用NSPredicate返回true?,swift,nspredicate,Swift,Nspredicate,这是我的密码: let newPredicate = NSPredicate(format: "true == %@") let y = newPredicate.evaluate(with: true) print(y) 它总是返回false 如何使用NSPredicate返回true?占位符%@用于传递给NSPredicate(格式:)调用的参数,如下所示: let newPredicate = NSPredicate(format: "true == %@", true

这是我的密码:

let newPredicate = NSPredicate(format: "true == %@")        
let y = newPredicate.evaluate(with: true)

print(y)
它总是返回
false


如何使用
NSPredicate
返回
true

占位符
%@
用于传递给
NSPredicate(格式:)
调用的参数,如下所示:

let newPredicate = NSPredicate(format: "true == %@", true)
如果要使用传递给
评估(with:)
的对象,请使用
self

let newPredicate = NSPredicate(format: "true == self")
let y = newPredicate.evaluate(with: true)
print(y)

如果要查找始终计算为true的默认谓词或回退谓词:

NSPredicate.init(值:true)