【发布时间】:2018-07-24 06:40:26
【问题描述】:
我在目标 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 中 IsSynced 值为 0 的数组元素,如下所示。
{
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 的新手。
【问题讨论】:
-
你的 NSLog 有正确的值 IsSynced = 0;那么有什么问题呢?
-
@Vinodh 我没有得到值为 IsSynced = 0 的数组元素;它只是将 NSArray *notsyncedenvds 的元素作为 o 元素提供,而不是它应该获得值为 IsSynced = 0 的 1 元素;从数组元素列表中,并在 Nslog 中显示
-
我刚刚提到了第二个数组元素作为我应该在我的 NSlog 中获取的示例。请查看我的代码@Vinodh
-
那么你应该用 IsSynced == 0 而不是 IsSynced == 1 格式更改谓词
标签: ios objective-c arrays nslog