问题
I'm using NSMapTable in a program that must run under both 3.0 and 2.2.1. As expected, the program compiles without problems for the 2.2.1 libraries, but when I switch to 3.0, I get compiler errors:
error: expected specifier-qualifier-list before 'NSMapTable'
In other words, XCode can't find the declaration of the NSMapTable class. I had to put in a forward declaration (@class NSMapTable) in my own header and
#import <Foundation/NSMapTable.h>
in my implementation file in order to be able to use NSMapTable.
Any explanations for this? Or is it just a bug, plain and simple?
(I should point out that I do, of course, have #import in the header file of the class that uses NSMapTable, but still need the specific import.)
回答1:
I don't believe NSMapTable was available on 2.2 for apps compiled for "Device", either; it was only available on "Simulator". Since 3.0's simulator is a more accurate representation of the device, that header is no longer available. Fortunately, you can do much of what an NSMapTable can do with an NSDictionary and appropriate NSValue or NSNumber wrapper objects around keys and values.
来源:https://stackoverflow.com/questions/1095368/nsmaptable-missing-from-3-0-headers