简体   繁体   English

CloudKit NSPredicate不区分大小写

[英]CloudKit NSPredicate case insensitive

I have a cloud kit query that uses the NSPredicate below to search for records where the name begins with the value the user enters into the UITextField . 我有一个云工具查询,使用下面的NSPredicate搜索名称以用户输入到UITextField的值开头的记录。 I would like to make the search case insensitive so if the user searched for "apple" it would display results for "Apple" and "apple". 我想使搜索不区分大小写,因此,如果用户搜索“ apple”,它将显示“ Apple”和“ apple”的结果。 How can I do this? 我怎样才能做到这一点? I have also tried to change the query to CONTAINS instead of BEGINSWITH but the app returns no results as it is looking for the value in an array. 我还尝试将查询更改为CONTAINS而不是BEGINSWITH但是该应用程序在数组中查找值时未返回任何结果。 Is it possible to see if the string contains the text field string? 是否可以查看字符串是否包含文本字段字符串? Thanks 谢谢

var p = NSPredicate(format: "name BEGINSWITH %@", titleLabel.text!)

As per the CKQuery docs : 根据CKQuery 文档

For fields that contain string values, you can match the beginning portion of the string using the BEGINSWITH operator as shown in Listing 4. You cannot use other string comparison operators such as CONTAINS or ENDSWITH. 对于包含字符串值的字段,可以使用BEGINSWITH运算符匹配字符串的开头部分,如清单4所示。不能使用其他字符串比较运算符,例如CONTAINS或ENDSWITH。 When using this operator, the field must contain a string value and must start with the string you specified. 使用此运算符时,该字段必须包含一个字符串值,并且必须以您指定的字符串开头。 Matches are case sensitive. 匹配区分大小写。 In the examples, the predicate matches records whose favoriteColors field contained the strings red, reddish, or red green duct tape. 在示例中,谓词匹配记录,其记录的“最喜欢的颜色”字段包含字符串red,reddish或red green的胶带。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM