Skip to content

Instantly share code, notes, and snippets.

@derickito
Created October 24, 2018 00:21
Show Gist options
  • Save derickito/d78a8b53493035e86e977c17ea381eb9 to your computer and use it in GitHub Desktop.
Save derickito/d78a8b53493035e86e977c17ea381eb9 to your computer and use it in GitHub Desktop.
Function to find the annotations that intersect with an array of selections using Apple's PDFKit in iOS
func annotationsIn(selections: [PDFSelection]) -> [PDFAnnotation] {
if selections.count == 0 { return [] }
var results: [PDFAnnotation] = []
for selection in selections {
//See if rect matches the annotations in this page
let page = selection.pages.first!
let bounds = selection.bounds(for: page)
for annotation in page.annotations {
if bounds.intersects(annotation.bounds) {
results.append(annotation)
}
}
}
return results
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment