MBFileReadOperation Class Reference
Inherits from | NSOperation |
---|---|
Declared in | MBFilesystemOperations.h |
Overview
An NSOperation
subclass that can be used to read file data.
MBFileReadOperation
instances are added to NSOperationQueue
s to be
performed, and the MBFileReadOperationDelegate
associated with the
operation is notified on the main thread when the operation completes
successfully or fails.
The MBFilesystemOperationQueue
singleton is available as a convenience
for performing filesystem operations such as this.
Object lifecycle
+ operationForReadingFromFile:delegate:
Creates a new MBFileReadOperation
instance that can be used to read the
contents of the file specified.
+ (nonnull instancetype)operationForReadingFromFile:(nonnull NSString *)path delegate:(nonnull NSObject<MBFileReadOperationDelegate> *)delegate
Parameters
path |
The filesystem path of the file to be read by the returned operation. |
---|---|
delegate |
The delegate that will be notified upon completion of the returned operation. |
Return Value
The newly-created MBFileReadOperation
instance.
Declared In
MBFilesystemOperations.h
– initForFilePath:delegate:
Initializes the receiver so it can be used to read from the specified file.
- (nonnull instancetype)initForFilePath:(nonnull NSString *)path delegate:(nonnull NSObject<MBFileReadOperationDelegate> *)delegate
Parameters
path |
The filesystem path of the file to be read by the receiver. |
---|---|
delegate |
The delegate that will be notified upon completion of the operation. |
Return Value
The receiver.
Declared In
MBFilesystemOperations.h
Getting information about the operation
filePath
Returns the filesystem path of the file to be read by the operation.
@property (nonnull, nonatomic, readonly) NSString *filePath
Declared In
MBFilesystemOperations.h
delegate
Returns the MBFileReadOperationDelegate
that will be notified when the
operation completes.
@property (nonnull, nonatomic, readonly) NSObject<MBFileReadOperationDelegate> *delegate
Declared In
MBFilesystemOperations.h
Subclassing hooks
– readObjectFromFile:error:
Called internally to read the file and convert its data into an object.
- (nullable id)readObjectFromFile:(nonnull NSString *)path error:(NSErrorPtrPtr)errPtr
Parameters
path |
The filesystem path of the file to read. |
---|---|
errPtr |
If this method returns |
Return Value
The object that was read from the file.
Discussion
The default implementation returns an NSData
instance. Subclasses may
override this method to return other types of objects.
Declared In
MBFilesystemOperations.h
– readCompletedWithObject:
Called internally when readObjectFromFile:error:
completes successfully.
- (void)readCompletedWithObject:(nonnull id)readObj
Parameters
readObj |
The object that was read from the filesystem, as returned
by |
---|
Discussion
Warning: Subclasses may override this method to perform additional work when
the operation completes, but must call super
to ensure that
the operation’s delegate is notified.
Declared In
MBFilesystemOperations.h
– readFailedWithError:
Called internally when readObjectFromFile:error:
fails.
- (void)readFailedWithError:(nonnull NSError *)err
Parameters
err |
The error describing the reason that |
---|
Discussion
Warning: Subclasses may override this method to perform additional work when
the operation completes, but must call super
to ensure that
the operation’s delegate is notified.
Declared In
MBFilesystemOperations.h