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 ...
随机推荐
- 【转】JavaScript 高性能数组去重
原文地址:https://www.cnblogs.com/wisewrong/p/9642264.html 一.测试模版 数组去重是一个老生常谈的问题,网上流传着有各种各样的解法 为了测试这些解法的性 ...
- CSP-S2019 自闭记
$Day0:$ 最后一场zr十连测从200挂到60,嘴上说着攒rp心里觉得药丸. 得知自己在本校考试感觉8错. $Day1:$ 早上7点50到了校门口,没让进QAQ早知道我再下一把棋了. 于是跟熊聊天 ...
- 『Blocks 区间dp』
Blocks Description Some of you may have played a game called 'Blocks'. There are n blocks in a row, ...
- 《PHP7底层设计与源码实现》学习笔记1——PHP7的新特性和源码结构
<PHP7底层设计与源码实现>一书的作者陈雷亲自给我们授课,大佬现身!但也因此深感自己基础薄弱,遂买了此书.希望看完这本书后,能让我对PHP7底层的认识更上一层楼.好了,言归正传,本书共1 ...
- java版的状态机实现
状态机适用场景: C的操作,需要等到A.B的两个操作(A.B顺序操作),那就需要在 A.B之间创建一个状态机(state machine),C的操作需要状态机达到某一个状态才能进行 1. Overvi ...
- 封装:WPF中可以绑定的BindPassWord控件
原文:封装:WPF中可以绑定的BindPassWord控件 一.目的:本身自带的PassWord不支持绑定 二.Xaml部分 <UserControl x:Class="HeBianG ...
- 好用的数据库字典查看工具SQLToolbelt
工作中经常为诸多的陌生或没有任何表或者字段说明或者文档庞大数据库和数据库表所烦恼,有以下场景: 1.新进入一家公司,开始接触新的项目,领导给你一大堆文档,在不了解具体逻辑的情况下,除了项目的结构,能让 ...
- Linux(Ubuntu)通过nfs挂载远程硬盘
需求 现有两台Linux Server,需要把Linux01 下的8T硬盘挂在到 Linux02 下:Linux01 硬盘: Linux02 硬盘: 挂载原理 通过 nfs-server 将Linux ...
- 指针总结指向const的指针、const指针、指向const指针的const指针
指针的一些总结 const与指针 指向const的指针指的是指针指向的数据是常量,不可以被修改,但指针变量本身可以被修改,如const int *p:严格说不能用指针间接修改指向的数据,但该变量可 ...
- Spring Security 解析(七) —— Spring Security Oauth2 源码解析
Spring Security 解析(七) -- Spring Security Oauth2 源码解析 在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因 ...