iphone - break iteration of photos ALAssetsLibrary -


how break through enumeration going on alassetslibrary enumerateassets method boolean set. can out of loop?

code:

[self.library enumerategroupswithtypes:alassetsgroupsavedphotos usingblock:^(alassetsgroup *group, bool *stop) {     @try {         if(group != nil) {             @autoreleasepool {                     int newnumberofphotos = [group numberofassets];                     if (self.numberofphotosinsavedphotos < newnumberofphotos) {                         //only new photos                          nsrange range = nsmakerange(self.numberofphotosinsavedphotos, newnumberofphotos-self.numberofphotosinsavedphotos);                         nsindexset *indexset = [nsindexset indexsetwithindexesinrange:range];                         [group enumerateassetsatindexes:indexset options:0 usingblock:^(alasset *result, nsuinteger index, bool *stop) {                             @autoreleasepool {                                if(somecondition)  {  //get out of enumeration block (that is, exit method) or go complete block                                 }                                  nsstring *assettype = [result valueforproperty:alassetpropertytype];                             }                         } ];                }                      }         } else {             //enumeration ended          }      }     @catch (nsexception *e) {         nslog(@"exception streaming: %@", [e description]);     } }failureblock:^(nserror *error){     nslog(@"error retrieving albums stream: %@", [error description]);     if (error.code==-3312  || error.code==-3311) {     } }]; 

to stop assets enumeration, set *stop = yes in enumeration block.

if want stop both outer , inner enumeration, use different names stop variable , set both yes:

[self.library enumerategroupswithtypes:alassetsgroupsavedphotos usingblock:^(alassetsgroup *group, bool *outerstop) {     ...     [group enumerateassetsatindexes:indexset options:0 usingblock:^(alasset *result, nsuinteger index, bool *innerstop) {          if (somecondition) {              *innerstop = yes;              *outerstop = yes;          } else {              // process asset          }      }  } 

remarks: @try/@catch block should not necessary if don't have programming error inside loops.

your check "new photos" looks suspicious, because number of assets in each group compared same number self.numberofphotosinsavedphotos, perhaps should check part again.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

python - cx_oracle unable to find Oracle Client -