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 ...
随机推荐
- python入门之名称空间的查找顺序
名称空间的查找顺序: 局部:局部 > 全局 > 内置 全局:全局 > 内置 # 内置再找不到就报错 # 函数内部使用的名字,在定义阶段已经规定死了,与你的调用位置无关 x = 111 ...
- angular JS中 ‘=’与angular.copy的区别
先来看代码: <b>{{test1}}</b> <input type="text" ng-model="test2" title ...
- [转帖]ORACLE 12C连接时报ORA28040和ORA01017的错误
ORACLE 12C连接时报ORA28040和ORA01017的错误 http://blog.itpub.net/12679300/viewspace-2150667/ 我一直在的处理方式是让更新or ...
- CSP2019-S游记
目录 CSP2019-S游记 Day -2(UPDATE:2019-11-14) Day -1(UPDATE:2019-11-15) Day 1(UPDATE:2019-11-16) Day 2(UP ...
- 『异或粽子 堆 可持久化trie』
异或粽子 Description 小粽是一个喜欢吃粽子的好孩子.今天她在家里自己做起了粽子. 小粽面前有 n 种互不相同的粽子馅儿,小粽将它们摆放为了一排,并从左至右编号为 1 到 n.第 i 种馅儿 ...
- - Gradle 翻译 Analyzer APK文件分析 MD
目录 目录 APK文件分析 使用 APK 分析器分析您的编译版本 查看文件和大小信息 查看 AndroidManifest.xml 查看 DEX 文件 过滤DEX文件树视图 加载 Proguard 映 ...
- .net HttpClient 回传实体帮助类
public class HttpClientHelper<T> { /// <summary> /// Get请求 返回实体 /// </summary> /// ...
- docker学习之路-nginx镜像(翻译)
本篇来自https://hub.docker.com/_/nginx/?tab=description 它是docker hub上nginx的官方网站,上面有关于nginx的使用描述等.从这里你可以找 ...
- 2019 花椒直播java面试笔试题 (含面试题解析)
本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.花椒直播等公司offer,岗位是Java后端开发,因为发展原因最终选择去了花椒直播,入职一年时间了,也成为了面 ...
- 为什么会有jQuery、Dojo、Ext、Prototype、YUI、Zepto这么多JS包?
目前流行的JS框架很多Dojo .Scriptaculous .Prototype .yui-ext .Jquery .Mochikit.mootools .moo.fx 等.当然还有很多我都不熟悉的 ...