Thursday, August 12, 2010

Don't forget your implicit casts

I recently answered a question on the apple forums regarding an error that arose from passing an NSDictionary object to a function that requires a CFDictionaryRef, although apple states that they are a toll free bridge to eachother, you still need to implicitly cast them.

example:
NSDictionary * someNSDictionary = [[NSDictionary alloc]initWithContentsOfFile:@"/SomePath"];
CFDictionaryRef someCFDictionary = (CFDictionaryRef)someNSDictionary;

3 comments:

  1. I tried this and it didn't work; is the capitalization on the second line necessary?

    ReplyDelete
  2. Yes, did you import CoreFoundation/CoreFoundation.h

    ReplyDelete
  3. Based on your other posts I'm going to assume you are working on a PC, in which case none of these posts will apply. Most of my posts are in Obj-C and the ones that are in C pertain only to a UNIX environment.

    ReplyDelete