# MGLOfflinePack

    @interface MGLOfflinePack : NSObject

An `MGLOfflinePack` represents a collection of resources necessary for viewing a region offline to a local database.

To create an instance of `MGLOfflinePack`, use the `+[MGLOfflineStorage addPackForRegion:withContext:completionHandler:]` method. A pack created using `-[MGLOfflinePack init]` is immediately invalid.

### Example

    MGLOfflineStorage.shared.addPack(for: region, withContext: context) { (pack, error) in
        guard let pack = pack else {
            // If adding the pack fails, log an error to console.
            print("Error:", error?.localizedDescription ?? "unknown error adding pack at \(#file)(\(#line)) in \(#function)")
            return
        }

        // Start an MGLOfflinePack download
        pack.resume()
    }

- `region`

  The region for which the pack manages resources.

  #### Declaration

  Objective-C

      @property (readonly, nonatomic) id<MGLOfflineRegion> _Nonnull region;

  Swift

      var region: MGLOfflineRegion { get }

  View Source on GitHub
- `context`

  Arbitrary data stored alongside the downloaded resources.

  The context typically holds application-specific information for identifying the pack, such as a user-selected name.

  #### Declaration

  Objective-C

      @property (readonly, nonatomic) NSData *_Nonnull context;

  Swift

      var context: Data { get }

  View Source on GitHub
- `state`

  The pack’s current state.

  The state of an inactive or completed pack is computed lazily and is set to `MGLOfflinePackStateUnknown` by default. To request the pack’s status, use the `-requestProgress` method. To get notified when the state becomes known and when it changes, observe KVO change notifications on this pack’s `state` key path. Alternatively, you can add an observer for `MGLOfflinePackProgressChangedNotification`s about this pack that come from the default notification center.

  #### Declaration

  Objective-C

      @property (readonly, nonatomic) MGLOfflinePackState state;

  Swift

      var state: MGLOfflinePackState { get }

  View Source on GitHub
- `progress`

  The pack’s current progress.

  The progress of an inactive or completed pack is computed lazily, and all its fields are set to 0 by default. To request the pack’s progress, use the `-requestProgress` method. To get notified when the progress becomes known and when it changes, observe KVO change notifications on this pack’s `state` key path. Alternatively, you can add an observer for `MGLOfflinePackProgressChangedNotification`s about this pack that come from the default notification center.

  #### Declaration

  Objective-C

      @property (readonly, nonatomic) MGLOfflinePackProgress progress;

  Swift

      var progress: MGLOfflinePackProgress { get }

  View Source on GitHub
- `-resume`

  Resumes downloading if the pack is inactive.

  When a pack resumes after being suspended, it may begin by iterating over the already downloaded resources. As a result, the `progress` structure’s `countOfResourcesCompleted` field may revert to 0 before rapidly returning to the level of progress at the time the pack was suspended.

  To temporarily suspend downloading, call the `-suspend` method.

  #### Declaration

  Objective-C

      - (void)resume;

  Swift

      func resume()

  View Source on GitHub
- `-suspend`

  Temporarily stops downloading if the pack is active.

  A pack suspends asynchronously, so some network requests may be sent after this method is called. Regardless, the `progress` property will not be updated until `-resume` is called.

  If the pack previously reached a higher level of progress before being suspended, it may wait to suspend until it returns to that level.

  To resume downloading, call the `-resume` method.

  #### Declaration

  Objective-C

      - (void)suspend;

  Swift

      func suspend()

  View Source on GitHub
- `-requestProgress`

  Request an asynchronous update to the pack’s `state` and `progress` properties.

  The state and progress of an inactive or completed pack are computed lazily. If you need the state or progress of a pack whose `state` property is currently set to `MGLOfflinePackStateUnknown`, observe KVO change notifications on this pack’s `state` key path, then call this method. Alternatively, you can add an observer for `MGLOfflinePackProgressChangedNotification` about this pack that come from the default notification center.

  #### Declaration

  Objective-C

      - (void)requestProgress;

  Swift

      func requestProgress()

  View Source on GitHub