TICDSOperation Class Reference
Inherits from | NSOperation |
Declared in | TICDSOperation.h |
Overview
The TICDSOperation
class provides the abstract behavior typical of any operation used by the TICoreDataSync
framework.
All TICoreDataSync
operations are (in Apple terms) concurrent, which means that they return YES
for isConcurrent
. This means they may be used by classes using e.g. NSURLConnection
or custom rest clients to fetch information in the background.
Subclasses should make use of the operation phase methods listed below to update the values of isExecuting
and isFinished
so that operation queues can keep track of them. The operationDidStart
method is called automatically when the operation begins to execute.
Subclasses of TICDSOperation
should override needsMainThread
to return YES
if they require their tasks to be implemented on the main thread.
The start
method automatically sets up the operation and notifies its delegate
that it started. Subclasses should override main
to do their work.
If an operation needs to create temporary files on disk during execution, it can call tempFileDirectoryPath
to get access to a directory created specifically for the operation. This directory (and its contents) will automatically be removed from disk once the operation calls one of the completion methods.
Subclasses must call one of the operationDidCompleteSuccessfully
, operationDidFailToComplete
or operationWasCancelled
to update the delegate and set the necessary values such that the operation be removed from the operation queue.
Tasks
Designated Initializer
-
– initWithDelegate:
Initialize the operation with a provided delegate, notified when the operation starts, ends, fails, or is cancelled using methods defined in the
TICDSOperationDelegate
protocol.
Operation Phase Updates
-
– operationDidStart
Notify the delegate when the operation starts, and set the necessary values for
isExecuting
andisFinished
. -
– operationDidCompleteSuccessfully
Notify the delegate when the operation completes, and set the necessary values for
isExecuting
andisFinished
. -
– operationDidFailToComplete
Notify the delegate if the operation has failed for some reason. Set the relevant
error
property before calling this method. This will set the required values forisExecuting
andisFinished
. -
– operationWasCancelled
Call this method if the operation is cancelled midway through its work. This will set the required values for
isExecuting
andisFinished
.
Properties
-
shouldUseEncryption
Used to indicate whether the operation should encrypt files stored on the remote.
property -
cryptor
The
propertyFZACryptor
object used to encrypt and decrypt files used by this operation, ifshouldUseEncryption
isYES
. -
delegate
The operation delegate.
property -
userInfo
A user info dictionary for sync managers to keep task-specific information.
property -
needsMainThread
By default returns
propertyNO
, but override if your operation needs its code to execute on the main thread, such as for anNSURLConnection
. -
isExecuting
Indicates the operation is currently executing; this is set automatically through the operation phase methods.
property -
isFinished
Indicates the operation has completed; this is set automatically through the operation phase methods.
property -
error
The most recent error; set this before calling
propertyoperationDidFailToComplete
. -
fileManager
An
propertyNSFileManager
object suitable for use by this operation. -
tempFileDirectoryPath
The path to a directory inside
propertyNSTemporaryDirectory()
guaranteed to be unique to this operation, created when path first requested and removed when operation finishes. -
clientIdentifier
The identifier of the client application (not set automatically, but may be used whenever necessary by subclasses).
property
Properties
clientIdentifier
The identifier of the client application (not set automatically, but may be used whenever necessary by subclasses).
@property (retain) NSString *clientIdentifier
Declared In
TICDSOperation.h
cryptor
The FZACryptor
object used to encrypt and decrypt files used by this operation, if shouldUseEncryption
is YES
.
@property (nonatomic, retain) FZACryptor *cryptor
Declared In
TICDSOperation.h
delegate
The operation delegate.
@property (nonatomic, assign) NSObject<TICDSOperationDelegate> *delegate
Declared In
TICDSOperation.h
error
The most recent error; set this before calling operationDidFailToComplete
.
@property (retain) NSError *error
Declared In
TICDSOperation.h
fileManager
An NSFileManager
object suitable for use by this operation.
@property (nonatomic, readonly, retain) NSFileManager *fileManager
Declared In
TICDSOperation.h
isExecuting
Indicates the operation is currently executing; this is set automatically through the operation phase methods.
@property (readonly) BOOL isExecuting
Declared In
TICDSOperation.h
isFinished
Indicates the operation has completed; this is set automatically through the operation phase methods.
@property (readonly) BOOL isFinished
Declared In
TICDSOperation.h
needsMainThread
By default returns NO
, but override if your operation needs its code to execute on the main thread, such as for an NSURLConnection
.
@property (readonly) BOOL needsMainThread
Declared In
TICDSOperation.h
shouldUseEncryption
Used to indicate whether the operation should encrypt files stored on the remote.
@property (assign) BOOL shouldUseEncryption
Declared In
TICDSOperation.h
Instance Methods
initWithDelegate:
Initialize the operation with a provided delegate, notified when the operation starts, ends, fails, or is cancelled using methods defined in the TICDSOperationDelegate
protocol.
- (id)initWithDelegate:(NSObject<TICDSOperationDelegate> *)aDelegate
Parameters
- aDelegate
The delegate object for the operation.
Return Value
A properly-initialized operation.
Declared In
TICDSOperation.h
operationDidCompleteSuccessfully
Notify the delegate when the operation completes, and set the necessary values for isExecuting
and isFinished
.
- (void)operationDidCompleteSuccessfully
Declared In
TICDSOperation.h
operationDidFailToComplete
Notify the delegate if the operation has failed for some reason. Set the relevant error
property before calling this method. This will set the required values for isExecuting
and isFinished
.
- (void)operationDidFailToComplete
Declared In
TICDSOperation.h
operationDidStart
Notify the delegate when the operation starts, and set the necessary values for isExecuting
and isFinished
.
- (void)operationDidStart
Discussion
This method is called automatically by TICDSOperation
when the operation starts to execute, so you should not call it from a TICDSOperation
subclass.
Declared In
TICDSOperation.h
operationWasCancelled
Call this method if the operation is cancelled midway through its work. This will set the required values for isExecuting
and isFinished
.
- (void)operationWasCancelled
Declared In
TICDSOperation.h