Receiver 'ClassName' is a forward class an

2020-06-09 04:39发布

问题:

Im currently trying to find a UIPickerTable within the UIPickerView.subviews ... so i loop through and do isKindOfClass:[UIPickerTable class] .... which works.. but because the header of UIPickerTable isn't exposed i get a warning that "receiver 'UIPickerTable' is a forward class and corresponding @interface may not exist'

In order to even be able to compile I do @class UIPickerTable, and obviously it want's me to #include it.

I'm wondering if there's a way to get around seeing this warning.

TIA!

回答1:

I don't think that you can suppress that warning with a compiler option. You could make it go away by simply creating your own header file for the class, containing:

@interface FacesViewController : NSObject {
}

I suppose it goes without saying that having your application depend on the internal structure of a UIKit class is probably not the best strategy. Presumably you have a good reason for mucking about inside the UIPicker...



回答2:

Maybe you have @class UIPickerTable in your .h file and you did not have #import UIPickerTable.h on your {RootViewController}.m file



回答3:

Importing the class vs using the @class directive will solve this warning. Remember, @class doesn't tell the compiler what "signature" methods/classes have, instead it just says that the class exists so don't error out. When going into detail, use import "..." instead so it includes the header / interface for the class.



回答4:

Using private APIs in an iPhone application is grounds for rejection from the AppStore (Google's proximity sensing feature not withstanding). Unless you plan to only use the software yourself, don't use private APIs. If there is no way to do what you want without resorting to private APIs, file a bug on Apple's radar.



回答5:

I may be totally missing the point here, but I came across something similar with AddressBook. I had included the AddressBook framework like so

#import <AddressBook/ABAddressBook.h>

But when I wanted to check on the class of the selected record in the peoplePickerView ..

NSArray *selected = [peoplePickerView selectedRecords];
for(id record in selected)
{
if([record isKindOfClass:[ABPerson class]])
{
    return [record valueForKey:@"identityUniqueId"];
}

}

...I got the warning that "receiver 'ABPerson' is a forward class and corresponding @interface may not exist". However, this proved easily fixed by adjusting the header file:

#import <AddressBook/ABAddressBook.h>
#import <AddressBook/ABPerson.h>
@class ABPerson;


回答6:

This kind of thing happens when the correct headers aren't imported sometime. E.g when trying to set an NSManagedObjectContext you might get that by not importing #import <CoreData/CoreData.h>