PSPDFLibraryDataSource

Objective-C

@protocol PSPDFLibraryDataSource <NSObject>

Swift

protocol LibraryDataSource : NSObjectProtocol

The PSPDFLibraryDataSource protocol is adopted by an object that provides the documents to be indexed by a PSPDFLibrary. These methods will not be called on the main queue, and can take long to execute. If you are implementing this protocol yourself and not using PSPDFLibraryFileSystemDataSource, please read the documentation carefully.

  • Notifies the data source that the library is about to begin the indexing process. Perform any required setup here.

    Declaration

    Objective-C

    - (void)libraryWillBeginIndexing:(nonnull PSPDFLibrary *)library;

    Swift

    optional func libraryWillBeginIndexing(_ library: PDFLibrary)

    Parameters

    library

    The library that is about to begin indexing.

  • Called after the library indexes a document.

    Note

    Implement this method on your data source instead of listening for the PSPDFLibraryDidFinishIndexingDocument notification. If the given document is the last one to be indexed, the library calls the completion handler passed in to its -updateIndexWithCompletionHandler: methods. This method gives your data source a chance to finish any bookkeeping so as to ensure that its state is up to date when the completion handler is called.

    Declaration

    Objective-C

    - (void)library:(nonnull PSPDFLibrary *)library
        didFinishIndexingDocumentWithUID:(nonnull NSString *)UID
                                 success:(BOOL)success;

    Swift

    optional func library(_ library: PDFLibrary, didFinishIndexingDocumentWithUID UID: String, success: Bool)

    Parameters

    library

    The library that finished indexing the document.

    UID

    The UID of the document that finished indexing.

    success

    Specifies whether the library successfully indexed the document.

  • Called after the library removes a document from its index.

    Declaration

    Objective-C

    - (void)library:(nonnull PSPDFLibrary *)library
        didRemoveDocumentWithUID:(nonnull NSString *)UID;

    Swift

    optional func library(_ library: PDFLibrary, didRemoveDocumentWithUID UID: String)

    Parameters

    library

    The library that removed the document.

    UID

    The UID of the document that was removed.

  • Asks the data source for the UIDs of the documents to be indexed by the library. This method should not return any uids that are already indexed, or they will be reindexed. This is useful in cases when the document was modified, and its contents changed and therefore need the index to be updated as well.

    Declaration

    Objective-C

    - (nonnull NSArray<NSString *> *)uidsOfDocumentsToBeIndexedByLibrary:
        (nonnull PSPDFLibrary *)library;

    Swift

    func uidsOfDocumentsToBeIndexed(by library: PDFLibrary) -> [String]

    Parameters

    library

    The library object requesting this information.

    Return Value

    An array of NSStrings each corresponding to the a Document UID.

  • Asks the data source for the UIDs for documents to be removed. This method will be called by the library at the start of its indexing process to allow for removal of any non-existing documents. This is especially necessary when the indexToSpotlight property is set to YES, as having deleted documents show up in indexed spotlight search is not good.

    Declaration

    Objective-C

    - (nonnull NSArray<NSString *> *)uidsOfDocumentsToBeRemovedFromLibrary:
        (nonnull PSPDFLibrary *)library;

    Swift

    func uidsOfDocumentsToBeRemoved(from library: PDFLibrary) -> [String]

    Parameters

    library

    The library object requesting this information.

    Return Value

    An array of NSStrings each corresponding to a previously indexed Document UID.

  • Asks the data source for a document with the specified UID.

    Warning

    This method may be called even without libraryWillBeginIndexing: being called first, if a document is required for Spotlight.

    Declaration

    Objective-C

    - (nullable PSPDFDocument *)library:(nonnull PSPDFLibrary *)library
                        documentWithUID:(nonnull NSString *)UID;

    Swift

    func library(_ library: PDFLibrary, documentWithUID UID: String) -> PSPDFDocument?

    Parameters

    library

    The library that requires the document.

    UID

    The UID of the requested document.

    Return Value

    A document with a matching UID, or nil if no such document exists.