字面量:

字符串:单引号或双引号扩起来;

%@:系统自动添加,数字则自动去除@();

无单双引号,系统做数字处理。

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.

  • %K is 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 与字面量的更多相关文章

  1. 字面量(literal)与 C 语言复合字面量(compound literals)

    在计算机科学中,字面量(literal)是用于表达源代码中一个固定值的表示法(notation)(字面量是相对变量常量等定义的,无论是常量还是变量,其值在某一时刻总是确定的,只是变量可以反复赋值.刷新 ...

  2. JavaScript 语法——字面量,变量,操作符,语句,关键字,注释,函数,字符集

    JavaScript 是一个程序语言. 语法规则定义了语言结构. 它是一个轻量级,但功能强大的编程语言.   ㈠JavaScript 字面量 在编程语言中,一般固定值称为字面量,如 3.14. ⑴数字 ...

  3. Java - String 的字面量、常量池、构造函数和intern()函数

    一.内存中的 String 对象 Java 的堆和栈 对于基本数据类型变量和对象的引用,也就是局部变量表属于栈内存: 而通过 new 关键字和 constructor 创建的对象存放在堆内存: 直接的 ...

  4. Java 中 String 的字面量与 intern 方法

    下方代码主要说明: String b = new String("xyz")  创建2个对象,一个在常量池中的 "xyz",一个 String 实例对象,返回的 ...

  5. String字面量

    public class assa{ static String ee = "aa";//ee指向常量池中的aa static String ff = new String(&qu ...

  6. String 的字面量、常量池、构造函数和intern()函数

    一.内存中的 String 对象 Java 的堆和栈 对于基本数据类型变量和对象的引用,也就是局部变量表属于栈内存: 而通过 new 关键字和 constructor 创建的对象存放在堆内存: 直接的 ...

  7. java基础---->string字面量的使用

    这里简单的理解一下java中关于string字面量的知识,关于字节码可以使用java自带的javap工具查看. string字面量 一.直接贴出测试的代码 A string literal alway ...

  8. 浅析Objective-C字面量

    编写Objective-C程序时,总会用到某几个类,它们属于Foundation框架.虽然从技术上来说,不用Foundation框架也能写出Objective-C代码,但实际上却经常要用到此框架.这几 ...

  9. C++11中的小细节--字符串的原始字面量

    原始字面量很容易理解,即不进行转义的完整字符串. 最近看了看Python,其中讲到了原始字符串. Both string and bytes literals may optionally be pr ...

随机推荐

  1. yum 删除了,如何重新导入

    说明:准备研究docker时遇到的问题,提示如下: [root@localhost116 yum-package]# rpm -ivh yum--.el6.centos.noarch.rpm warn ...

  2. 如何删除docker镜像中已配置的volume

    场景: 有个同学不知道因为啥,将容器内部的 /sys/fs/cgroup 挂载到了外面的某个目录: 但是这个目录是很有用的,不想随便被挂载,如何从image中去掉呢? docker没有给出一个方便的方 ...

  3. Java学习:抽象方法和抽象类的使用

    抽象 抽象方法:就是加上abstract关键字,然后去掉大括,直接分号结束.抽象类:抽象方法所在的类,必须是抽象类才行.在class之前写上abstract即可. 如何使用抽象类和抽象方法: 1.不能 ...

  4. 安装软件时出现这样错误:文件“proe50-1a.bin”无法在“C:\User\ZFTL\Desktop\proe50”定位,请插入正确的磁盘或选择其他文件夹

    把里面的文件改成proe50-1a.bin就可以了.

  5. syntax error near unexpected token 脚本报错误解决

    hadoop老师给了一个shell文件,在windows里面瞅了一眼然后在ubuntu环境下运行就报错了.看了一些博客,用vim -b filename查看的时候发现每一行的末尾都多了一个^M.... ...

  6. 递归求兔子数列第n项的值

    #include <iostream> using namespace std; int f(int n)//递归f数列的第n项 { ,y=,z; ||n==) { ; } else { ...

  7. Navicat 破解版(操作非常简单)

    Navicat 破解版(操作非常简单) 参考这位老哥的博客,之前试过好多个,只有这个是最简单有效的 https://blog.csdn.net/WYpersist/article/details/86 ...

  8. 一,python编程100例

    1.有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? #有1.2.3.4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? number = (1 ,2,3,4) ...

  9. 安装vivado 2016.1时出错

    在将vivado 2016.1安装到d:\ xilinx时,发生以下错误: 提取存档D时遇到 错误:\ Xilinx_Vivado_SDK_2016.1_0409_1 \ payload \ rdi_ ...

  10. 修改docker容器参数

    创建容器时没有添加参数  --restart=always ,导致的后果是:当 Docker 重启时,容器未能自动启动. docker container update --restart=alway ...