ILPDFKit icon indicating copy to clipboard operation
ILPDFKit copied to clipboard

Sequence Protocol

Open shnabz opened this issue 8 years ago • 5 comments

Hi, when trying to iterate through the form container I get: Type 'ILPDFFormContainer?' does not conform to protocol 'Sequence' Any thoughts?

shnabz avatar Jun 13 '17 15:06 shnabz

Any idea? I have the same problem!

fboemeke avatar Jul 18 '17 00:07 fboemeke

I have ended up opening my pdf in Adobe Acrobat and making a note of all the form fields ID, I then use these strings to refer to the form fields which works fine.

shnabz avatar Jul 18 '17 16:07 shnabz

Thanks @shnabz! I've used the same solution although I'm looking for a dynamic solution.

fboemeke avatar Jul 18 '17 16:07 fboemeke

@fboemeke I've found a solution! Add this extension to your .swift file.

extension ILPDFFormContainer: Sequence {
    public func makeIterator() -> NSFastEnumerationIterator {
        return NSFastEnumerationIterator(self as NSFastEnumeration)
    }
}

You can then do:

for form in document.forms {
    let x = form as! ILPDFForm
    print(x.name)
}

shnabz avatar Jul 18 '17 21:07 shnabz

@shnabz Thank you!

fboemeke avatar Jul 19 '17 11:07 fboemeke