小编Gab*_*ega的帖子

NSPredicate predicateWithFormat:argumentArray:仅评估第一个参数

我在使用时遇到了一些麻烦NSPredicate predicateWithFormat:argumentArray:.在此示例中,serverIDList是字符串数组.结果是一个包含NSManagedObjects名为"flid"的属性的数组,该属性是一个字符串.

NSMutableString *predicateString = [[NSMutableString alloc] init];

[predicateString appendString:@"(flid IN %@)"];

[results filterUsingPredicate:[NSPredicate predicateWithFormat:predicateString argumentArray:serverIDList]];
Run Code Online (Sandbox Code Playgroud)

问题是[NSPredicate predicateWithFormat:predicateString argumentArray:serverIDList]评估为"flid IN'2155'",这只是数组的第一个值serverIDList.我似乎无法获得谓词来评估整个数组.这里有什么东西不见了吗?

谢谢!

core-data nspredicate ios

6
推荐指数
1
解决办法
8167
查看次数

适用于iOS的SQLite事务语法

我想循环遍历一个对象数组,并根据ID更新SQLite数据库中的相应行.我想在一次交易中这样做.我知道我可以用:

sqlite3_exec(db, "BEGIN", 0, 0, 0);
sqlite3_exec(db, "COMMIT", 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)

但是,我不确定如何在事务内部编写更新语句.我需要将不同的变量绑定到语句中.现在代码看起来像这样:

-(void)someUpdateMethod
{
    sqlite3 *db;

    //Establish connection to db
    if (sqlite3_open([[self dbFilePath] UTF8String], &db) == SQLITE_OK)
    {
        const char *query = "UPDATE Table SET Value1 = ?, Value2 = ?";

        sqlite3_stmt *compiledStatement = nil;

        sqlite3_exec(db, "BEGIN EXCLUSIVE TRANSACTION", 0, 0, 0);
        for (someObject *obj in uArray)
        {
            // Repeated statement - This is what I'm not sure of...
            if(sqlite3_prepare(db, query, -1, &compiledStatement, NULL) == SQLITE_OK)
            {
                sqlite3_bind_int(compiledStatement, 1, [obj …
Run Code Online (Sandbox Code Playgroud)

sqlite syntax transactions ios sql-update

2
推荐指数
1
解决办法
8673
查看次数

标签 统计

ios ×2

core-data ×1

nspredicate ×1

sql-update ×1

sqlite ×1

syntax ×1

transactions ×1