Predicate Format String Syntax 与字面量
字面量:
字符串:单引号或双引号扩起来;
%@:系统自动添加,数字则自动去除@();
无单双引号,系统做数字处理。
Single or double quoting variables (or substitution variable strings) cause %@, %K, or $variable to be interpreted as a literal in the format string and so prevent any substitution.
系统自动添加 double quoting
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K = %@", @"a", @"ddd"];
NSPredicate *predicatex = [NSPredicate predicateWithFormat:@"eee = %@", @"ddd"];
NSPredicate *predicateh = [NSPredicate predicateWithFormat:@"h = 'hhh'"];
NSPredicate *predicatee = [NSPredicate predicateWithFormat:@"%K = %@",@"c", @(7)];
NSPredicate *predicatep = [NSPredicate predicateWithFormat:@"%K = %d",@"e", 7];
NSLog(@"\r\n%@\r\n%@\r\n%@\r\n%@\r\n%@",predicate,predicatex,predicateh,predicatee,predicatep);
a == "ddd"
eee == "ddd"
h == "hhh"
c == 7
e == 7
NSPredicate *predicate = [NSPredicate predicateWithFormat:[NSString stringWithFormat:@"appId == '%@'", [FQAccountManager sharedFQAccountManager].appId]];
属于二次转化。
https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html#//apple_ref/doc/uid/TP40001795-SW1
Parser Basics
The predicate string parser is whitespace insensitive, case insensitive with respect to keywords, and supports nested parenthetical expressions. The parser does not perform semantic type checking.
Variables are denoted with a dollar-sign ($) character (for example, $VARIABLE_NAME). The question mark (?) character is not a valid parser token.
The format string supports printf-style format specifiers such as %x (see Formatting String Objects). Two important format specifiers are %@ and %K.
%@is a var arg substitution for an object value—often a string, number, or date.%Kis a var arg substitution for a key path.
When string variables are substituted into a string using the %@ format specifier, they are surrounded by quotation marks. If you want to specify a dynamic property name, use %K in the format string, as shown in the following example.
NSString *attributeName = @"firstName"; |
NSString *attributeValue = @"Adam"; |
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like %@", |
attributeName, attributeValue]; |
The predicate format string in this case evaluates to firstName like "Adam".
Single or double quoting variables (or substitution variable strings) cause %@, %K, or $variable to be interpreted as a literal in the format string and so prevent any substitution. In the following example, the predicate format string evaluates to firstName like "%@" (note the single quotes around %@).
NSString *attributeName = @"firstName"; |
NSString *attributeValue = @"Adam"; |
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"%K like '%@'", |
attributeName, attributeValue]; |
Predicate Format String Syntax 与字面量的更多相关文章
- 字面量(literal)与 C 语言复合字面量(compound literals)
在计算机科学中,字面量(literal)是用于表达源代码中一个固定值的表示法(notation)(字面量是相对变量常量等定义的,无论是常量还是变量,其值在某一时刻总是确定的,只是变量可以反复赋值.刷新 ...
- JavaScript 语法——字面量,变量,操作符,语句,关键字,注释,函数,字符集
JavaScript 是一个程序语言. 语法规则定义了语言结构. 它是一个轻量级,但功能强大的编程语言. ㈠JavaScript 字面量 在编程语言中,一般固定值称为字面量,如 3.14. ⑴数字 ...
- Java - String 的字面量、常量池、构造函数和intern()函数
一.内存中的 String 对象 Java 的堆和栈 对于基本数据类型变量和对象的引用,也就是局部变量表属于栈内存: 而通过 new 关键字和 constructor 创建的对象存放在堆内存: 直接的 ...
- Java 中 String 的字面量与 intern 方法
下方代码主要说明: String b = new String("xyz") 创建2个对象,一个在常量池中的 "xyz",一个 String 实例对象,返回的 ...
- String字面量
public class assa{ static String ee = "aa";//ee指向常量池中的aa static String ff = new String(&qu ...
- String 的字面量、常量池、构造函数和intern()函数
一.内存中的 String 对象 Java 的堆和栈 对于基本数据类型变量和对象的引用,也就是局部变量表属于栈内存: 而通过 new 关键字和 constructor 创建的对象存放在堆内存: 直接的 ...
- java基础---->string字面量的使用
这里简单的理解一下java中关于string字面量的知识,关于字节码可以使用java自带的javap工具查看. string字面量 一.直接贴出测试的代码 A string literal alway ...
- 浅析Objective-C字面量
编写Objective-C程序时,总会用到某几个类,它们属于Foundation框架.虽然从技术上来说,不用Foundation框架也能写出Objective-C代码,但实际上却经常要用到此框架.这几 ...
- C++11中的小细节--字符串的原始字面量
原始字面量很容易理解,即不进行转义的完整字符串. 最近看了看Python,其中讲到了原始字符串. Both string and bytes literals may optionally be pr ...
随机推荐
- 洛谷P5017:摆渡车——题解
https://www.luogu.org/problem/P5017 参考:https://www.luogu.org/blog/ztyluogucpp/solution-p5017 我想我大概是废 ...
- 【洛谷】P1478 陶陶摘苹果(升级版)-全AC题解
#include <iostream> #include <algorithm> using namespace std; int main() { int n,s,a,b; ...
- deepin安装卡在deepin标志界面解决方案
再次重启前将U盘插上,进系统前按快速选择启动装置F12(不同品牌电脑可能不同),选择从U盘启动: 进入第一个安装界面时一定要注意:在跳转前,按E进入grub设置界面,移动光标到倒数第二行的”quiet ...
- Markdown_word_chain_test2222
# Flutter ![Flutter logo][] [![Gitter Channel][]][Gitter badge] [![Build Status - Cirrus][]][Build ...
- 在ASP.NET Core中获取客户端和服务器端的IP地址(转载)
随着ASP.NET的发展,有不同的方式从请求中访问客户端IP地址.WebForms和MVC Web应用程序只是访问当前HTTP上下文的请求. var ip = HttpContext.Current. ...
- zabbix4.0 本地安装详解及步骤
安装前说明下,下面安装过程中涉及selinux部分仅供参考,可能会导致启动服务时产生各种报错,作者也是在折腾了无数日夜后报错不断而放弃治疗,直接永久关闭了selinux(啊,没有selinux的日子真 ...
- scratch学习研究心得_逐步更新
2019-10-30: Scratch对对象a克隆,不能选择克隆自己,这样可能下次一下子同时产生两个克隆体,要设置克隆a scratch3.0采用全新html5技术,图片和其他对象放大缩小,效果几乎不 ...
- 对比度增强(二):直方图正规划与伽马变换 cv.normal()函数使用及原理
直方图正规化: 图像为I,宽为W,高为H,I(r,c)代表I的第r行第c列的灰度值:输出图像记为O,为使得输出图像的灰度值在[Omin,Omax]范围里,可用如下公式: ...
- 多态性 类(class)的四则运算
我们知道c语言中可以整型数据或浮点型等做四则运算,而自己写的类也可做四则运算,是不是感觉奇怪,可以看以下代码是如何完成类之间的四则运算: #include "stdafx.h" ...
- Java 数组(三)二维数组
如果一维数组的各个元素仍然是一个数组,那么它就是一个二维数组.二维数组常用于表示表,表中的信息以行和列的形式组织,第一个下标代表元素所在的行,第二个下标代表所在的列. 一.二维数组的创建 1.先声明, ...