Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从select sqlite命令转换为NSPredicate命令_Iphone_Ios_Objective C_Sqlite_Core Data - Fatal编程技术网

Iphone 从select sqlite命令转换为NSPredicate命令

Iphone 从select sqlite命令转换为NSPredicate命令,iphone,ios,objective-c,sqlite,core-data,Iphone,Ios,Objective C,Sqlite,Core Data,我有这一行 [TableProperties setObject:[NSString stringWithFormat:@"username='%@' AND id IN (SELECT Max(id) FROM messages GROUP BY MD5) ",MobilyUserAccount] forKey:@"tableWhere"]; 我想将此选择行更改为 NSPredicate *findUser = [NSPredicate predicateWithFormat:@"user

我有这一行

[TableProperties setObject:[NSString stringWithFormat:@"username='%@' AND id IN (SELECT  Max(id) FROM messages GROUP BY MD5) ",MobilyUserAccount] forKey:@"tableWhere"];
我想将此选择行更改为

NSPredicate *findUser = [NSPredicate predicateWithFormat:@"username='%@' AND id IN (SELECT  id==max(id) FROM messages GROUP BY MD5)",MobilyUserAccount];
NSPredicate *findUser = [NSPredicate predicateWithFormat]
当我运行应用程序时,出现了这个错误

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to parse the format string "username='%@' AND id IN (SELECT  id==max(id) FROM messages GROUP BY MD5)"'
请我需要一个帮助来将第一行转换为

NSPredicate *findUser = [NSPredicate predicateWithFormat:@"username='%@' AND id IN (SELECT  id==max(id) FROM messages GROUP BY MD5)",MobilyUserAccount];
NSPredicate *findUser = [NSPredicate predicateWithFormat]

谢谢大家

您使用SQLite还是核心数据?如果这是针对SQLite的,则不能使用NSPredicate。如果问题是关于核心数据,那么你必须展示实体是如何定义的。我第一次使用SQLite时更新了我的应用程序,但现在我想使用核心数据。你能解释一下你在SQL的第二部分中做了什么吗,
SELECT id==max(id)FROM messages
你不能简单地将任意SQLite数据库转换为核心数据,并且不能将任意SELECT语句转换为NSPredicate。我不想听起来不友好,但您是否阅读了《核心数据编程指南》?您确定SQL查询中没有错误吗?我在这里解释,但MD5的组(如果是MD5哈希值)将返回与消息数量相同的记录,因为MD5值(很可能)是唯一的。还有什么ID是用户ID还是消息ID?无论如何,@Martin是对的。您将需要从头开始构建NSpredicate,这可能并不困难。