iOS Developer Library

Developer

AssetsLibrary Framework Reference ALAssetsGroup Class Reference

Options
Deployment Target:

On This Page
Language:

ALAssetsGroup

Inheritance


Conforms To


Import Statement


Swift

import AssetsLibrary

Objective-C

@import AssetsLibrary;

Availability


Available in iOS 4.0 and later.

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.

  • Adds an existing asset to the receiver.

    Declaration

    Swift

    func addAsset(_ asset: ALAsset!) -> Bool

    Objective-C

    - (BOOL)addAsset:(ALAsset *)asset

    Parameters

    asset

    The asset to add to the receiver.

    Return Value

    YEStrue if asset was added successfully, otherwise NOfalse.

    Discussion

    The method may fail (return NOfalse) 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.

    Import Statement

    Objective-C

    @import AssetsLibrary;

    Swift

    import AssetsLibrary

    Availability

    Available in iOS 5.0 and later.

  • editable editable Property

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

    Declaration

    Swift

    var editable: Bool { get }

    Objective-C

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

    Discussion

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

    Import Statement

    Objective-C

    @import AssetsLibrary;

    Swift

    import AssetsLibrary

    Availability

    Available in iOS 5.0 and later.

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

    Declaration

    Swift

    func numberOfAssets() -> Int

    Objective-C

    - (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

    Import Statement

    Objective-C

    @import AssetsLibrary;

    Swift

    import AssetsLibrary

    Availability

    Available in iOS 4.0 and later.

  • Sets the filter for the group.

    Declaration

    Swift

    func setAssetsFilter(_ filter: ALAssetsFilter!)

    Objective-C

    - (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.

    Import Statement

    Objective-C

    @import AssetsLibrary;

    Swift

    import AssetsLibrary

    Availability

    Available in iOS 4.0 and later.

  • Returns the group’s value for a given property.

    Declaration

    Swift

    func valueForProperty(_ property: String!) -> AnyObject!

    Objective-C

    - (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

    Import Statement

    Objective-C

    @import AssetsLibrary;

    Swift

    import AssetsLibrary

    Availability

    Available in iOS 4.0 and later.

  • Returns the group’s poster image

    Declaration

    Swift

    func posterImage() -> Unmanaged<CGImage>!

    Objective-C

    - (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).

    Import Statement

    Objective-C

    @import AssetsLibrary;

    Swift

    import AssetsLibrary

    Availability

    Available in iOS 4.0 and later.

Data Types

  • Signature for the block executed during enumeration of assets.

    Declaration

    Swift

    typealias ALAssetsGroupEnumerationResultsBlock = (ALAsset!, Int, UnsafeMutablePointer<ObjCBool>) -> Void

    Objective-C

    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 YEStrue to stop the enumeration.

    The value is set to YEStrue 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 YEStrue.

    Import Statement

    Objective-C

    @import AssetsLibrary;

    Swift

    import AssetsLibrary

    Availability

    Available in iOS 4.0 and later.

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

    Declaration

    Swift

    let ALAssetsGroupPropertyName: String let ALAssetsGroupPropertyType: String let ALAssetsGroupPropertyPersistentID: String let ALAssetsGroupPropertyURL: String

    Objective-C

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

    Constants

    • ALAssetsGroupPropertyName

      ALAssetsGroupPropertyName

      Key to retrieve the name of the group.

      The corresponding value is an NSString object.

      Available in iOS 4.0 and later.

    • ALAssetsGroupPropertyType

      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.

    • ALAssetsGroupPropertyPersistentID

      ALAssetsGroupPropertyPersistentID

      Key to retrieve the group’s persistent ID.

      The corresponding value is an NSString object.

      Available in iOS 4.0 and later.

    • ALAssetsGroupPropertyURL

      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.