字面量:

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

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

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

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. [转帖] db file sequential read及优化

    http://blog.itpub.net/12679300/viewspace-1185623/ db file sequential read及优化 原创 Oracle 作者:wzq609 时间: ...

  2. jmeter 生成不重复的手机号

    String account = "${__time(yyyyMMdd,)}"+UUID.randomUUID().toString().split("-")[ ...

  3. 核与线程 CPU 4核8线程 的解释

    1.物理CPU: 物理CPU就是计算机上实际配置的CPU个数.在linux上可以打开cat /proc/cpuinfo 来查看,其中的physical id就是每个物理CPU的ID,能找到几个phys ...

  4. 让div在body中任意拖动

    HTML代码 <div id="idOuterDiv" class="CsOuterDiv"> </div> CSS代码 body { ...

  5. C#使用SMTP协议发送验证码到QQ邮箱

    C#使用SMTP协议发送验证码到QQ邮箱 在程序设计中,发送验证码是常见的一个功能,用户在注册账号时或忘记密码后,通常需要发送验证码到手机短信或邮箱来验证身份,此篇博客介绍在C#中如何使用SMTP协议 ...

  6. JS this指向总结

    使用 JavaScript 开发的时候,很多开发者多多少少会被 this 的指向搞蒙圈,但是实际上,关于 this 的指向,记住最核心的一句话:哪个对象调用函数,函数里面的this指向哪个对象. 下面 ...

  7. Cheat Engine 特征码

    打开游戏 引用自动注入 搜索特征码 特征码,是游戏运行中,唯一的汇编代码 验证,特征码是游戏中唯一代码 添加特征码 添加特征码,以及金钱只增不减代码 进行激活测试 特征码,只有在游戏过程中才会执行到 ...

  8. YUV视频格式详解(翻译自微软文档)

    原文: https://docs.microsoft.com/en-us/previous-versions/aa904813(v=vs.80) YUV视频格式详解(翻译自微软文档)https://b ...

  9. 一次 Young GC 的优化实践(FinalReference 相关)

    本文转载自公众号:涤生的博客,阅读时间大约需要11分钟.涤生的文章看起来跟破案一样,很精彩,很有启发. 前言 博客已经好久没有更新了,主要原因是 18 年下半年工作比较忙,另外也没有比较有意思的题材, ...

  10. 为什么Audition CC2017扫描不了电音插件,你需要这个工具

    一时兴起,我也去下载并安装了Audition的音频后期处理软件,版本是cc2017.简单熟悉了对自己声音修理外,我还想添加一点电音的效果显得洋气一些.在网上下载并安装了warves tune后,发现A ...