为了扩展开源项目的功能,我编写了一个用于添加新方法的类别。在这个新方法中,类需要从原来的类中访问一个内部方法,但是编译器却说找不到该方法(当然是内部的)。有没有办法为类别公开这个方法?
编辑
我不想修改原代码,所以不想在原类头文件中声明内部方法。
编码
在原始类实现文件(.m)中,我有这个方法实现:
+(NSDictionary*) storeKitItems
{
return [NSDictionary dictionaryWithContentsOfFile:
[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
@"MKStoreKitConfigs.plist"]];
}
在类别中,我想添加这个方法:
- (void)requestProductData:(NSArray *(^)())loadIdentifierBlock
{
NSMutableArray *productsArray = [NSMutableArray array];
NSArray *consumables = [[[MKStoreManager storeKitItems] objectForKey:@"Consumables"] allKeys];
NSArray *nonConsumables = [[MKStoreManager storeKitItems] objectForKey:@"Non-Consumables"];
NSArray *subscriptions = [[[MKStoreManager storeKitItems] objectForKey:@"Subscriptions"] allKeys];
if(loadIdentifierBlock != nil) [productsArray addObjectsFromArray:loadIdentifierBlock()];
[productsArray addObjectsFromArray:consumables];
[productsArray addObjectsFromArray:nonConsumables];
[productsArray addObjectsFromArray:subscriptions];
self.productsRequest.delegate = self;
[self.productsRequest start];
}
在我调用storeKitItems
编译器的每一行中都说:找不到类方法“+storeKitItems”...