过滤NS数组,根据issynced值获取元素
Filtering the NS array and getting the element according to the issynced value
我在 objective c 工作。在这里,我需要在我的 NSlog 中包含 IsSynced = 0 的数组元素。我需要过滤 resultArry.
{
ActivityTime = "2018-07-24T05:48:25.017Z";
EntityId = "B88476DA-3707-4B37-A1E0-142875CFAE6E";
ErrorCode = "<null>";
ErrorData = "<null>";
ErrorMessage = "<null>";
IsSynced = 0;
Message = "Waybill 'QBZZ222220180724111804' created.";
PropertyId = "8c0ad0da-4505-40d5-8201-a7818a3d055a";
PropertyPIC = QBZZ2222;
RecentActivityId = "79A6E4D7-2D60-4635-9A70-C4E55D5A1399";
TableNames = NVD;
},
{
ActivityTime = "2018-07-23T11:31:25.905Z";
EntityId = "23AE3D5E-8423-428F-9678-7BB3A75EF320";
ErrorCode = "<null>";
ErrorData = "<null>";
ErrorMessage = "<null>";
IsSynced = 1;
Message = "Waybill 'QBZZ222220180723170035' created.";
PropertyId = "8c0ad0da-4505-40d5-8201-a7818a3d055a";
PropertyPIC = QBZZ2222;
RecentActivityId = "2C3C7047-F43C-4521-8B66-419AF31EC766";
TableNames = NVD;
},
{
ActivityTime = "2018-07-23T09:44:32.483Z";
EntityId = "49914A90-8F05-4479-B2C8-49C34637E70B";
ErrorCode = "<null>";
ErrorData = "<null>";
ErrorMessage = "<null>";
IsSynced = 1;
Message = "Waybill 'QBZZ222220180723151237' created.";
PropertyId = "8c0ad0da-4505-40d5-8201-a7818a3d055a";
PropertyPIC = QBZZ2222;
RecentActivityId = "DCCF5B03-7AD3-404F-A235-006DF3A37F97";
TableNames = NVD;
},
这是我的代码
SArray *resultArry = [[DBHelper getSharedInstance] getRecordsBySQL:propertyQuery];
//NSString *recentactivitylog=[[NSString alloc] initWithData:resultArry encoding:NSUTF8StringEncoding];
NSLog(@"This is the eNVDS in Recent Activity:%@" ,resultArry);
NSPredicate *notsynced = [NSPredicate predicateWithFormat:
@"resultArry.IsSynced = 1"];
NSArray *notsyncedenvds = [resultArry filteredArrayUsingPredicate:notsynced];
NSLog(@"This is the eNVDS in Recent Activity which is not synced:%@" ,notsyncedenvds);
我只需要在我的 NSlog 中具有值为 0 的 IsSynced 的数组元素,您可以在下面看到这个元素。
{
ActivityTime = "2018-07-24T05:48:25.017Z";
EntityId = "B88476DA-3707-4B37-A1E0-142875CFAE6E";
ErrorCode = "<null>";
ErrorData = "<null>";
ErrorMessage = "<null>";
IsSynced = 0;
Message = "Waybill 'QBZZ222220180724111804' created.";
PropertyId = "8c0ad0da-4505-40d5-8201-a7818a3d055a";
PropertyPIC = QBZZ2222;
RecentActivityId = "79A6E4D7-2D60-4635-9A70-C4E55D5A1399";
TableNames = NVD;
}
我不知道我的代码有什么问题我在过滤谓词后没有得到任何元素。抱歉,我是 Objective-c.
的新手
NSPredicate *notsynced = [NSPredicate predicateWithFormat:
@"IsSynced == 0 || IsSynced == %@",@"0"];
NSArray *notsyncedenvds = [resultArry filteredArrayUsingPredicate:notsynced];
NSLog(@"This is the eNVDS in Recent Activity which is not synced:%@" ,notsyncedenvds);
或
对于大量数据的快速枚举
NSMutableArray *arr = [[NSMutableAraay alloc]init];
for(NSDictionary *dict in resultArry){
NSString *IsSynced = [NSStrinf StringWithFormat:@"%@",[dict objectforkey:@"IsSynced"]];
if([IsSynced integerValue] = 0){
[arr addObject:dict];
}
}
NSLog(@"IsSynced zero value array %@",arr);
谓词错误。您不得包含数组本身
NSPredicate *notsynced = [NSPredicate predicateWithFormat: @"IsSynced = 1"];
但是由于您需要带有 IsSynced = 0
的项目,因此您必须过滤以下内容:
NSPredicate *notsynced = [NSPredicate predicateWithFormat: @"IsSynced = 0"];
如果键 IsSynced
的值是一个字符串,您必须添加单引号
NSPredicate *notsynced = [NSPredicate predicateWithFormat: @"IsSynced = '0'"];
我在 objective c 工作。在这里,我需要在我的 NSlog 中包含 IsSynced = 0 的数组元素。我需要过滤 resultArry.
{
ActivityTime = "2018-07-24T05:48:25.017Z";
EntityId = "B88476DA-3707-4B37-A1E0-142875CFAE6E";
ErrorCode = "<null>";
ErrorData = "<null>";
ErrorMessage = "<null>";
IsSynced = 0;
Message = "Waybill 'QBZZ222220180724111804' created.";
PropertyId = "8c0ad0da-4505-40d5-8201-a7818a3d055a";
PropertyPIC = QBZZ2222;
RecentActivityId = "79A6E4D7-2D60-4635-9A70-C4E55D5A1399";
TableNames = NVD;
},
{
ActivityTime = "2018-07-23T11:31:25.905Z";
EntityId = "23AE3D5E-8423-428F-9678-7BB3A75EF320";
ErrorCode = "<null>";
ErrorData = "<null>";
ErrorMessage = "<null>";
IsSynced = 1;
Message = "Waybill 'QBZZ222220180723170035' created.";
PropertyId = "8c0ad0da-4505-40d5-8201-a7818a3d055a";
PropertyPIC = QBZZ2222;
RecentActivityId = "2C3C7047-F43C-4521-8B66-419AF31EC766";
TableNames = NVD;
},
{
ActivityTime = "2018-07-23T09:44:32.483Z";
EntityId = "49914A90-8F05-4479-B2C8-49C34637E70B";
ErrorCode = "<null>";
ErrorData = "<null>";
ErrorMessage = "<null>";
IsSynced = 1;
Message = "Waybill 'QBZZ222220180723151237' created.";
PropertyId = "8c0ad0da-4505-40d5-8201-a7818a3d055a";
PropertyPIC = QBZZ2222;
RecentActivityId = "DCCF5B03-7AD3-404F-A235-006DF3A37F97";
TableNames = NVD;
},
这是我的代码
SArray *resultArry = [[DBHelper getSharedInstance] getRecordsBySQL:propertyQuery];
//NSString *recentactivitylog=[[NSString alloc] initWithData:resultArry encoding:NSUTF8StringEncoding];
NSLog(@"This is the eNVDS in Recent Activity:%@" ,resultArry);
NSPredicate *notsynced = [NSPredicate predicateWithFormat:
@"resultArry.IsSynced = 1"];
NSArray *notsyncedenvds = [resultArry filteredArrayUsingPredicate:notsynced];
NSLog(@"This is the eNVDS in Recent Activity which is not synced:%@" ,notsyncedenvds);
我只需要在我的 NSlog 中具有值为 0 的 IsSynced 的数组元素,您可以在下面看到这个元素。
{
ActivityTime = "2018-07-24T05:48:25.017Z";
EntityId = "B88476DA-3707-4B37-A1E0-142875CFAE6E";
ErrorCode = "<null>";
ErrorData = "<null>";
ErrorMessage = "<null>";
IsSynced = 0;
Message = "Waybill 'QBZZ222220180724111804' created.";
PropertyId = "8c0ad0da-4505-40d5-8201-a7818a3d055a";
PropertyPIC = QBZZ2222;
RecentActivityId = "79A6E4D7-2D60-4635-9A70-C4E55D5A1399";
TableNames = NVD;
}
我不知道我的代码有什么问题我在过滤谓词后没有得到任何元素。抱歉,我是 Objective-c.
的新手 NSPredicate *notsynced = [NSPredicate predicateWithFormat:
@"IsSynced == 0 || IsSynced == %@",@"0"];
NSArray *notsyncedenvds = [resultArry filteredArrayUsingPredicate:notsynced];
NSLog(@"This is the eNVDS in Recent Activity which is not synced:%@" ,notsyncedenvds);
或
对于大量数据的快速枚举
NSMutableArray *arr = [[NSMutableAraay alloc]init];
for(NSDictionary *dict in resultArry){
NSString *IsSynced = [NSStrinf StringWithFormat:@"%@",[dict objectforkey:@"IsSynced"]];
if([IsSynced integerValue] = 0){
[arr addObject:dict];
}
}
NSLog(@"IsSynced zero value array %@",arr);
谓词错误。您不得包含数组本身
NSPredicate *notsynced = [NSPredicate predicateWithFormat: @"IsSynced = 1"];
但是由于您需要带有 IsSynced = 0
的项目,因此您必须过滤以下内容:
NSPredicate *notsynced = [NSPredicate predicateWithFormat: @"IsSynced = 0"];
如果键 IsSynced
的值是一个字符串,您必须添加单引号
NSPredicate *notsynced = [NSPredicate predicateWithFormat: @"IsSynced = '0'"];