ios - 数组中最后添加的对象

标签 ios objective-c nsarray

<分区>

if (sqlite3_prepare_v2(dbHandlerPointerNote ,selectQuery , -1, &prepareStmtNote, NULL) == SQLITE_OK)                     {
            while (sqlite3_step(prepareStmtNote) == SQLITE_ROW)

        {
            NSString *noteName = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(prepareStmtNote, 0)];
            [_notesArray addObject:noteName];
            int noteid =sqlite3_column_int(prepareStmtNote, 1);
            [_noteidArray  addObject:[NSString stringWithFormat:@"%d",noteid]];
            NSString *noteDate = [[NSString alloc]initWithUTF8String:(const char *) sqlite3_column_text(prepareStmtNote,2)];
            [_notesDate addObject:noteDate];
            // arrObj is a mutable arr

        }
    }

上面是我如何将对象添加到 note_id 数组。

这是我试图获取最后一个对象的方式:

_savedNoteid1=[[_modleClass.noteidArray lastObject]intValue];

但它不能正常工作。如何获取数组中的最后一个对象?

最佳答案

i want to get what the object added to last to the array how is it possible.....

如果你只想访问 NSArray(或 NSMutableArray)实例中的最后一个对象,你可以简单地使用 -lastObject 方法:

id item = [someArray lastObject];

关于ios - 数组中最后添加的对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15308312/

上一篇:ios - 如何在 UITableView 中的图像中添加事件指示器?

下一篇:ios - 转换为二进制 - long long 和 NSUInteger

相关文章:

ios - 禁用 firebase 自动屏幕报告

ios - SQLite 查询占用太多 CPU

iphone - 相对于 iPad 和 iPhone 放置图像

iphone - iOS 如何在没有堆栈跟踪的情况下调试崩溃,如 : [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array?

iOS:使用 .xcconfig 文件指定代码签名身份

ios - Phonegap:下载当前设置的证书和配置

iphone - 如何将应用程序从旧 iPhone 移植到 iPhone 4? (Retina显示屏)

iPhone : How to separate string like "ListName|Definition|Answer"

objective-c - 如何根据 NSArray 的元素选择方法 (Objective-C)

xcode - 按字典中的 NSDates 对字典数组进行排序