title: How to retrieve all the photos and videos in an array from Photos library?
body: <p>In my code I have tried to fetch all the photos from the photo library and store them in an array.
  I want to fetch even the videos also and store them in the same array.
  Please tell me how to modify this code for the above requirement.
  I have been struggling for this since months as I am a newbie.</p>
  
  <pre><code>-(IBAction)getAllPictures: (id) sender
  {
      imageArray=[[NSArray alloc] init];
      mutableArray =[[NSMutableArray alloc]init];
      NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];
  
      library = [[ALAssetsLibrary alloc] init];
  
      void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop)
      {
          if(result != nil)
          {
              if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto])
              {
                  if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeVideo])
                  {
  
                    if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypeUnknown])
                    {
                      [assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];
  
                      NSURL *url= (NSURL*) [[result defaultRepresentation]url];
  
                      [library assetForURL:url
                       resultBlock:^(ALAsset *asset)
                       {
                           [mutableArray addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];
  
                           if ([mutableArray count]==count)
                           {
                               imageArray=[[NSArray alloc] initWithArray:mutableArray];
                               [self allPhotosCollected:imageArray];
                           }
                       }
                      failureBlock:^(NSError *error){ NSLog(@"operation was not successfull!");
                      } ];
  
          }
      }
  }
  }
  };
  
  NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
  
  void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop)
  {
      if(group != nil)
      {
          [group enumerateAssetsUsingBlock:assetEnumerator];
          [assetGroups addObject:group];
          count=[group numberOfAssets];
      }
  };
  
  assetGroups = [[NSMutableArray alloc] init];
  
  [library enumerateGroupsWithTypes:ALAssetsGroupAll
                         usingBlock:assetGroupEnumerator
                       failureBlock:^(NSError *error)
  {
      NSLog(@"There is an error");
  }];
  }
  
  -(void)allPhotosCollected:(NSArray*)imgArray
  {
  //write your code here after getting all the photos from library...
      NSLog(@"all pictures are %@",imgArray);
  }
  </code></pre>