ios - PHFetchOptions predicate with NSDate compare -


hello had been working photos.framework stuck predicate comparison of phfetchoptions class in documents see can use startdate use in predicate. code

@interface viewcontroller () {     nsmutablearray * moments; }    @end  @implementation viewcontroller  - (void)viewdidload {     [super viewdidload];     // additional setup after loading view, typically nib.     moments = [nsmutablearray array];      if([phphotolibrary authorizationstatus] == phauthorizationstatusnotdetermined)     {         [phphotolibrary requestauthorization:^(phauthorizationstatus status) {             [self loadcollections];         }];     }else     {         [self loadcollections];     }  }  - (void)viewwillappear:(bool)animated {     [super viewwillappear:animated];     [self loadcollections]; }   - (nsdate*)dateaddingdays:(nsinteger)days todate:(nsdate*)argdate {     nscalendar * gregorian = [nscalendar currentcalendar];      nsdateformatter * formatter = [[nsdateformatter alloc]init];     [formatter setdateformat:@"dd.mm.yyyy"];     nsstring * datestring = [formatter stringfromdate:argdate];     nsdate * toworkdate = [formatter datefromstring:datestring];      nsdatecomponents *comps = [[nsdatecomponents alloc] init];     [comps setday:days];     nsdate *date = [gregorian datebyaddingcomponents:comps todate:toworkdate  options:0];     nslog(@"%@",[formatter stringfromdate:date]);     return date; }  - (void)loadcollections {     phfetchoptions * options = [[phfetchoptions alloc]init];      options.predicate = [nscomparisonpredicate predicatewithformat:@"startdate > cast(%d,\"nsdate\")",[self dateaddingdays2:-1 todate:[nsdate date]].timeintervalsince1970];     phfetchresult * result = [phassetcollection fetchmomentswithoptions:options];      if(result != nil)     {         nslog(@"%i",result.count);         (int = 0; < result.count; i++) {             nslog(@"%@",[result objectatindex:i]);             [moments addobject:[result objectatindex:i]];         }     }  } 

so problem this, need fetch fotos 1 day ago, can make work!! appreciated.

this answer, replaced

- (nsdate*)dateaddingdays:(nsinteger)days todate:(nsdate*)argdate {     nscalendar * gregorian = [nscalendar currentcalendar];      nsdateformatter * formatter = [[nsdateformatter alloc]init];     [formatter setdateformat:@"dd.mm.yyyy"];     nsstring * datestring = [formatter stringfromdate:argdate];     nsdate * toworkdate = [formatter datefromstring:datestring];      nsdatecomponents *comps = [[nsdatecomponents alloc] init];     [comps setday:days];     nsdate *date = [gregorian datebyaddingcomponents:comps todate:toworkdate  options:0];     nslog(@"%@",[formatter stringfromdate:date]);     return date; } 

by

- (nsdate*)yesterday {     nscalendar * gregorian = [nscalendar currentcalendar];     return [gregorian startofdayfordate:[gregorian datebyaddingunit:nscalendarunitday value:-1 todate:[nsdate date] options:nscalendarwrapcomponents]]; } 

and replace this

options.predicate = [nscomparisonpredicate predicatewithformat:@"startdate > cast(%d,\"nsdate\")",[self dateaddingdays2:-1 todate:[nsdate date]].timeintervalsince1970]; 

by this

options.predicate = [nscomparisonpredicate predicatewithformat:@"(startdate > %@)",[self yesterday]]; 

and working!!! @larme


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -