开发者

Debug / Release build differences for superclass / subclass

I have an iOS project which builds and executes as expected under debug yet throws a compilation error when being built for release. The error is to do with an iVar which is declared in a superclass and it is specifically

'fetchedResultsController_' undeclared (First use in this function).

Here is the superclass .h.

@interfa开发者_Python百科ce Super : UIViewController <NSFetchedResultsControllerDelegate> {
    NSFetchedResultsController* fetchedResultsController_;
    NSManagedObjectContext* managedObjectContext_;
}

@property (nonatomic, retain) NSFetchedResultsController* fetchedResultsController;
@property (nonatomic, retain) NSManagedObjectContext* managedObjectContext;

@end

and the superclass .m

@implementation Super

@synthesize fetchedResultsController = fetchedResultsController_;
@synthesize managedObjectContext = managedObjectContext_;

#pragma mark -
#pragma mark Properties

-(NSFetchedResultsController*)fetchedResultsController {
    return nil;
}

The Subclass interface is defined thus:-

@interface Sub : Super <UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate> {
    // extra stuff
}

In the subclass .m I implement lazy loading for fetchedResultsController

-(NSFetchedResultsController*)fetchedResultsController {

    if (fetchedResultsController_ == nil) { // undeclared error here....
    //stuff
    }
    return fetchedResultsController_;

I'm confused mainly because I don't understand why this would comile in Debug but not in Release!

If someone could identify what the issue is I'd appreciate it greatly


This isn't the answer to your question, but it will make the problem go away.

As things stand, in your Super class, having the instance variable at all is pointless. And you should probably set the property readOnly so people using it know that setting the fetchedResultController property is not allowed. As things stand, people have a reasonable expectation that if they set the property, they'll get more something back when they read it.

So, move the instance variable into the subclass. Declare the property readOnly in the superclass and redeclare it readWrite in the subclass.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜