There is a question about using Swift to get the dictionary keys from a PDF file here: How to get CGPDFDictionaryRef keys
An answer has been given, which is just one line of code, but I don't see how it fits with the original code in the question. Can anyone elaborate it?