ALAssetsGroup Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AssetsLibrary.framework
Availability
Available in iOS 4.0 and later.
Declared in
ALAssetsGroup.h
Related sample code

Overview

An ALAssetsGroup object represents an ordered set of the assets managed by the Photos application. The order of the elements is the same as the user sees in the Photos application. An asset can belong to multiple assets groups.

Assets groups themselves are synced via iTunes, created to hold the user’s saved photos or created during camera import. You can indirectly modify the Saved Photos group by saving images or videos into it using the ALAssetsLibrary class.

Tasks

Enumerating Assets

Adding Assets

Filtering

Accessing Properties

Properties

editable

Indicates whether the application can edit the group. (read-only)

@property(nonatomic, readonly, getter=isEditable) BOOL editable
Discussion

The value of the property is YES if the application is able to edit the group, otherwise it is NO.

Availability
  • Available in iOS 5.0 and later.
Declared In
ALAssetsGroup.h

Instance Methods

addAsset:

Adds an existing asset to the receiver.

- (BOOL)addAsset:(ALAsset *)asset
Parameters
asset

The asset to add to the receiver.

Return Value

YES if asset was added successfully, otherwise NO.

Discussion

The method may fail (return NO) if the group is not editable, or if the asset could not be added to the group.

You should check the editable property of the group to see if it is possible to add an asset to the group.

Availability
  • Available in iOS 5.0 and later.
Declared In
ALAssetsGroup.h

enumerateAssetsAtIndexes:options:usingBlock:

Invokes a given block using each of the assets in the group at specified indexes.

- (void)enumerateAssetsAtIndexes:(NSIndexSet *)indexSet options:(NSEnumerationOptions)options usingBlock:(ALAssetsGroupEnumerationResultsBlock)enumerationBlock
Parameters
indexSet

The indexes of the assets to enumerate.

The index set must not specify any indexes exceeding numberOfAssets.

options

Options for the enumeration.

enumerationBlock

The block to invoke using each of the assets in the group at the indexes in indexSet.

Discussion

Availability
  • Available in iOS 4.0 and later.
Declared In
ALAssetsGroup.h

enumerateAssetsUsingBlock:

Invokes a given block using each of the assets in the group.

- (void)enumerateAssetsUsingBlock:(ALAssetsGroupEnumerationResultsBlock)enumerationBlock
Parameters
enumerationBlock

The block to invoke using each of the assets in the group.

Discussion

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
ALAssetsGroup.h

enumerateAssetsWithOptions:usingBlock:

Invokes a given block using each of the assets in the group.

- (void)enumerateAssetsWithOptions:(NSEnumerationOptions)options usingBlock:(ALAssetsGroupEnumerationResultsBlock)enumerationBlock
Parameters
options

Options for the enumeration.

enumerationBlock

The block to invoke using each of the assets in the group.

Discussion

Availability
  • Available in iOS 4.0 and later.
Declared In
ALAssetsGroup.h

numberOfAssets

Returns the number of assets in the group that match the current filter.

- (NSInteger)numberOfAssets
Return Value

The number of assets in the group that match the current filter. If no filter is set, returns the count of all assets in the group.

Discussion

Availability
  • Available in iOS 4.0 and later.
Declared In
ALAssetsGroup.h

posterImage

Returns the group’s poster image

- (CGImageRef)posterImage
Return Value

The group’s poster image.

Discussion

The image is returned in the correct orientation (that is, “pointing up”—you shouldn’t have to rotate the image).

Availability
  • Available in iOS 4.0 and later.
Declared In
ALAssetsGroup.h

setAssetsFilter:

Sets the filter for the group.

- (void)setAssetsFilter:(ALAssetsFilter *)filter
Parameters
filter

The filter for the group.

Discussion

This method sets the filter the group; it does not execute the filter. The filter is applied when you invoke numberOfAssets or enumerate the contents.

If you don’t set the filter, or set it to nil, the enumeration returns all the assets in the group.

Special Considerations

Only one filter is active at a time. Any enumeration currently in flight continues to completion using the previous filter.

Availability
  • Available in iOS 4.0 and later.
Related Sample Code
Declared In
ALAssetsGroup.h

valueForProperty:

Returns the group’s value for a given property.

- (id)valueForProperty:(NSString *)property
Parameters
property

The name of a group property. For valid values, see “Group Property Names.”

Return Value

The group’s value for property.

Discussion

Availability
  • Available in iOS 4.0 and later.
Declared In
ALAssetsGroup.h

Constants

ALAssetsGroupEnumerationResultsBlock

Signature for the block executed during enumeration of assets.

typedef void (^ALAssetsGroupEnumerationResultsBlock)(ALAsset *result, NSUInteger index, BOOL *stop);
Discussion

The block takes the following arguments:

result

An asset that matches the filter set by the caller.

index

The index of the asset in the range being returned.

If no asset is found, index is set to NSNotFound.

stop

A pointer to a Boolean value that indicates whether the enumeration should stop. Set the referenced value to YES to stop the enumeration.

The value is set to YES if no asset is found.

If the application is not given access to the data, result is nil, index is NSNotFound, and stop points to YES.

Availability
  • Available in iOS 4.0 and later.
Declared In
ALAssetsGroup.h

Group Property Names

Constants for the names of group properties, used by valueForProperty:.

NSString *const ALAssetsGroupPropertyName;
NSString *const ALAssetsGroupPropertyType;
NSString *const ALAssetsGroupPropertyPersistentID;
NSString *const ALAssetsGroupPropertyURL;
Constants
ALAssetsGroupPropertyName

Key to retrieve the name of the group.

The corresponding value is an NSString object.

Available in iOS 4.0 and later.

Declared in ALAssetsGroup.h.

ALAssetsGroupPropertyType

Key to retrieve the group type.

The corresponding value is an ALAssetsGroupType constant wrapped in an NSNumber object.

Available in iOS 4.0 and later.

Declared in ALAssetsGroup.h.

ALAssetsGroupPropertyPersistentID

Key to retrieve the group’s persistent ID.

The corresponding value is an NSString object.

Available in iOS 4.0 and later.

Declared in ALAssetsGroup.h.

ALAssetsGroupPropertyURL

Key to retrieve a URL that uniquely identifies the group.

The corresponding value is an NSURL object.

Available in iOS 5.0 and later.

Declared in ALAssetsGroup.h.