MNFJob

Objective-C

@interface MNFJob : NSObject

Swift

class MNFJob : NSObject

The MNFJob class acts as a wrapper for the Bolts framework developed by Facebook.

A job contains a Bolts task and a task completion source both of which can be used to initialize a job. Additionally a job contains a reference to the URL request used to carry out server requests from the MNF framework. Therefore a server request can be cancelled if it has not completed by cancelling the job.

A job should not be directly initialized but should rather use a Bolts task tompletion source to initialize with.

  • @abstract A delegate for the job to call MNFJobDelegate protocol methods on. All methods in the protocol are optional.

    Declaration

    Objective-C

    @property (nonatomic, strong) id<MNFJobDelegate> _Nonnull delegate;

    Swift

    var delegate: MNFJobDelegate { get set }
  • @abstract The result of the jobs request.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) id _Nonnull result;

    Swift

    var result: Any { get }
  • @abstract Any metadata returned by the jobs request.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) id _Nonnull metaData;

    Swift

    var metaData: Any { get }
  • @abstract The error returned by the jobs request.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) NSError *_Nonnull error;

    Swift

    var error: Error { get }
  • @abstract Whether the job has been cancelled.

    Declaration

    Objective-C

    @property (nonatomic, readonly, getter=isCancelled) BOOL cancelled;

    Swift

    var isCancelled: Bool { get }
  • @abstract Whether the job has been completed.

    Declaration

    Objective-C

    @property (nonatomic, readonly, getter=isCompleted) BOOL completed;

    Swift

    var isCompleted: Bool { get }
  • @abstract Whether the job has been paused.

    Declaration

    Objective-C

    @property (nonatomic, readonly, getter=isPaused) BOOL paused;

    Swift

    var isPaused: Bool { get }
  • @abstract Whether the job has been resumed.

    Declaration

    Objective-C

    @property (nonatomic, readonly, getter=isResumed) BOOL resumed;

    Swift

    var isResumed: Bool { get }
  • @abstract A method for handling a job completion. @discussion Requests are performed using NSURLSession which normally uses a background thread to perform it’s requests. Therefore this method is performed on the current thread the request is performed on.

    Declaration

    Objective-C

    - (void)handleCompletion:(nonnull MNFJobCompletionHandler)completion;

    Swift

    func handleCompletion() async throws -> (Any, Any)

    Parameters

    completion

    A completion block returning a result, metadata and an error.

  • @abstract A method for handling a job completion on the main thread. @discussion Requests are performed using NSURLSession which normally uses a background thread to perform it’s requests. This method forces the execution of completion to be performed on the main thread and is useful when handling ui action upon completion.

    Declaration

    Objective-C

    - (void)handleMainThreadCompletion:(nonnull MNFJobCompletionHandler)completion;

    Swift

    func handleMainThreadCompletion() async throws -> (Any, Any)

    Parameters

    completion

    A completion block returning a reuslt, metadata and an error.

  • @abstract A method for handling a job cancellation.

    Declaration

    Objective-C

    - (void)cancelWithCompletion:(nonnull void (^)(void))completion;

    Swift

    func cancel() async

    Parameters

    completion

    A completion block which fires when the url session has finished cancelling the request.

  • @abstract A method for handling a job pausing.

    Declaration

    Objective-C

    - (void)pauseWithCompletion:(nonnull void (^)(void))completion;

    Swift

    func pause() async

    Parameters

    completion

    A completion block which fires when the url session has finished pausing the request.

  • @abstract A method for handling a job resuming.

    Declaration

    Objective-C

    - (void)resumeWithCompletion:(nonnull void (^)(void))completion;

    Swift

    func resume() async

    Parameters

    completion

    A completion block which fires when the url session has finished resuming the request.