0

I'm trying to create a PDF document in iOS using Quartz 2D. When I try to define a dictionary to set PDF metadata a get this error:

Cannot invoke 'CFDictionaryCreateMutable' with an argument list of type '(CFAllocator!, Int, CFDictionaryKeyCallBacks, CFDictionaryValueCallBacks)'

Here is how I defined my dictionary:

var documentInfo = CFDictionaryCreateMutable(kCFAllocatorDefault, 0, kCFTypeDictionaryKeyCallBacks, kCFTypeDictionaryValueCallBacks)
ABakerSmith
  • 22,759
  • 9
  • 68
  • 78
a0alv
  • 1
  • 4
  • 1
    You can/should create a Swift dictionary instead. See http://stackoverflow.com/questions/30143515/how-to-pass-parameter-of-type-unsafemutablepointerunsafepointervoid for a similar issue. – Martin R May 12 '15 at 14:18
  • Since I'm trying to set up my PDF context, how can I initialise the Auxiliary Dictionary Keys (kCGPDFContextAuthor, kCGPDFContextCreator, etc)? @Martin R – a0alv May 12 '15 at 18:02
  • @MartinR (you seem to know your way around Swift), have you any advice on CF dictionaries that take opaque keys that are otherwise non hashable on the Swift side? I am trying to port Obj-C code that has a dictionary mapping CTFont -> CGPath, and haven't wrapped my head around how Swift can create, cast or otherwise adapt these types. Specifically, is it better to create these dictionaries with the method above, and cast in later references, or to try to create swift dictionaries using hashable adapters to CF opaque types? (I can post a question for this, if it helps) - thanks. – Chris Conover Nov 02 '15 at 18:30

1 Answers1

1

First, create swift dictionary.

var wDict = [ "KEY": "VALUE" ]

And cast it to CFDictionaryRef when needed to create PDF.

var documentInfo = wDict as CFDictionaryRef
Satachito
  • 5,838
  • 36
  • 43