1

我有这个方法:

@implementation NSObject (defaultSelector)
+(NSDictionary *) idSelectorDictionary
{
    if (_idSelectors==nil)
    {
        NSMutableDictionary * IDSelectors = [NSMutableDictionary dictionary];
        IDSelectors[NSStringFromClass([DistanceGrouping class])]=NSStringFromSelector(@selector(Description));
        IDSelectors[NSStringFromClass([Business class])]=NSStringFromSelector(@selector(ID));
        IDSelectors[NSStringFromClass([Tag class])]=NSStringFromSelector(@selector(Name));
        IDSelectors[NSStringFromClass([Image class])]=NSStringFromSelector(@selector(URL));
        IDSelectors[NSStringFromClass([Alias class])]=NSStringFromSelector(@selector(stringAlias));
        IDSelectors[NSStringFromClass([City class])]=NSStringFromSelector(@selector(Name));
        IDSelectors[NSStringFromClass([Country class])]=NSStringFromSelector(@selector(Name));
        IDSelectors[NSStringFromClass([District class])]=NSStringFromSelector(@selector(ID));
        IDSelectors[NSStringFromClass([Phone class])]=NSStringFromSelector(@selector(thePhone));
        IDSelectors[NSStringFromClass([URL class])]=NSStringFromSelector(@selector(Name));
        IDSelectors[NSStringFromClass([KeyPhrase class])]=NSStringFromSelector(@selector(thekeyword));
        IDSelectors[NSStringFromClass([PlaceCache class])]=NSStringFromSelector(@selector(Text));
        IDSelectors[NSStringFromClass([BGCatalogData class])]=NSStringFromSelector(@selector(id));
        IDSelectors[NSStringFromClass([CategoryNearby class])]=NSStringFromSelector(@selector(imageNamed));
        IDSelectors[NSStringFromClass([Review class])]=NSStringFromSelector(@selector(ID));
        IDSelectors[NSStringFromClass([KeyPhrase class])]=NSStringFromSelector(@selector(thekeyword));
        IDSelectors[NSStringFromClass([AutoCompleteEntry class])]=NSStringFromSelector(@selector(idOfEntries));
        IDSelectors[NSStringFromClass([CDParent class])]=NSStringFromSelector(@selector(strParentId));
        _idSelectors = IDSelectors;
    }
    return _idSelectors;
}

那是NSObject的一个类别。为什么选择 NSObject?实际上我希望它是 NSManagedObject 的一个类别。

但是,如果我这样做,这些代码将不起作用:

+(void) debuggingToolsShowObjectsWithThisIDs: (NSArray *) localObjectIDs forClass: (Class) class
...
    NSPredicate * pred = [NSPredicate predicateWithFormat:@"%K in %@",class.defaultSelector,localObjectIDs];

我收到了这个错误:

/business/Dropbox/badgers/BadgerNew/BGMDCRManagedObjectContextThreadHandler.m:286:71:Objective-C 指针类型“Class”(又名“Class *”)到 C 指针类型“struct objc_class *”的隐式转换需要桥接转换

我可以将 (Class) 更改为 (NSManagedObjectSubclass) 之类的吗?

4

0 回答 0