PSPDFContainerAnnotationProvider


@interface PSPDFContainerAnnotationProvider
    : NSObject <PSPDFAnnotationProvider, PSPDFUndoSupport>

Default container for annotations. It’s crucial that you use this class as your base class if you implement a custom annotation provider, as this class offers efficient undo/redo which otherwise is almost impossible to replicate unless you understand the PSPDFKit internals extremely well.

  • Super needs to be called for undo/redo management.

    Declaration

    Objective-C

    - (nullable NSArray<__kindof PSPDFAnnotation *> *)
    addAnnotations:(nonnull NSArray<__kindof PSPDFAnnotation *> *)annotations
           options:(nullable NSDictionary<NSString *, id> *)options;
  • Super needs to be called for undo/redo management.

    Declaration

    Objective-C

    - (nullable NSArray<__kindof PSPDFAnnotation *> *)
    removeAnnotations:(nonnull NSArray<__kindof PSPDFAnnotation *> *)annotations
              options:(nullable NSDictionary<NSString *, id> *)options;
  • Allows synchronization with the internal reader queue. - warning: You shouldn’t call any of the methods below inside such synchronization blocks, or you will risk a deadlock.

    Declaration

    Objective-C

    - (void)performBlockForReading:(nonnull void (^)(void))block;

    Swift

    func performBlock(forReading block: @escaping () -> Void)
  • Allows synchronization with the internal writer queue.

    Declaration

    Objective-C

    - (void)performBlockForWriting:(nonnull void (^)(void))block;

    Swift

    func performBlock(forWriting block: @escaping () -> Void)
  • Allows synchronization with the internal writer queue and blocks until the block is processed.

    Declaration

    Objective-C

    - (void)performBlockForWritingAndWait:(nonnull void (^)(void))block;

    Swift

    func performBlock(forWritingAndWait block: @escaping () -> Void)
  • Modify the internal store. Optionally appends annotations instead of replacing them. - note: The page set in the annotations need to match the page.

    Declaration

    Objective-C

    - (void)setAnnotations:(nonnull NSArray<PSPDFAnnotation *> *)annotations
            forPageAtIndex:(NSUInteger)pageIndex
                    append:(BOOL)append;

    Swift

    func setAnnotations(_ annotations: [PSPDFAnnotation], forPageAt pageIndex: UInt, append: Bool)
  • Set annotations, evaluate the page value of each annotation.

    Declaration

    Objective-C

    - (void)setAnnotations:(nonnull NSArray<PSPDFAnnotation *> *)annotations
                    append:(BOOL)append;

    Swift

    func setAnnotations(_ annotations: [PSPDFAnnotation], append: Bool)
  • Remove all annotations (effectively clears the cache). - parameter: options Deletion options (see the PSPDFAnnotationOption... constants in PSPDFAnnotationManager.h).

    Declaration

    Objective-C

    - (void)removeAllAnnotationsWithOptions:
        (nonnull NSDictionary<NSString *, id> *)options;

    Swift

    func removeAllAnnotations(options: [String : Any] = [:])

    Parameters

    options

    Deletion options (see the PSPDFAnnotationOption... constants in PSPDFAnnotationManager.h).

  • Returns all annotations of all pages in one array.

    Declaration

    Objective-C

    @property (readonly, nonatomic)
        NSArray<PSPDFAnnotation *> *_Nonnull allAnnotations;

    Swift

    var allAnnotations: [PSPDFAnnotation] { get }
  • Returns all annotations as a page->annotations per page dictionary.

    Declaration

    Objective-C

    @property (readonly, nonatomic)
        NSDictionary<NSNumber *, NSArray<PSPDFAnnotation *> *>
            *_Nonnull annotations;

    Swift

    var annotations: [NSNumber : [PSPDFAnnotation]] { get }
  • Adding/Removing annotations triggers an internal flag that the provider requires saving. This method can clear this flag.

    Declaration

    Objective-C

    - (void)clearNeedsSaveFlag;

    Swift

    func clearNeedsSaveFlag()
  • May be used to override the annotation cache directly. Faster than using setAnnotations:.

    Declaration

    Objective-C

    - (void)setAnnotationCacheDirect:
        (nonnull NSDictionary<NSNumber *, NSArray<PSPDFAnnotation *> *> *)
            annotationCache;

    Swift

    func setAnnotationCacheDirect(_ annotationCache: [NSNumber : [PSPDFAnnotation]])
  • Registers annotations for the undo system. - warning: Ensure this is called within a write block!

    Declaration

    Objective-C

    - (void)registerAnnotationsForUndo:
        (nonnull NSArray<PSPDFAnnotation *> *)annotations;

    Swift

    func registerAnnotations(forUndo annotations: [PSPDFAnnotation])
  • Directly accesses the annotation cache used internally. Be extremely careful when accessing this, and use the locking methods.

    Declaration

    Objective-C

    @property (readonly, nonatomic)
        NSMutableDictionary<NSNumber *, NSArray<PSPDFAnnotation *> *>
            *_Nonnull annotationCache;

    Swift

    var annotationCache: NSMutableDictionary { get }
  • Called before new annotations are inserted. Subclass to perform custom actions.

    Declaration

    Objective-C

    - (void)willInsertAnnotations:(nonnull NSArray<PSPDFAnnotation *> *)annotations;

    Swift

    func willInsertAnnotations(_ annotations: [PSPDFAnnotation])