How to use different interface declarations at compile time without confusing the Builder interface

If I have several builds of my application, paid and free versions, for example, and I want to have different interfaces depending on which assembly seems to mess up the Builder interface.

For instance:

// MyViewController.h #ifdef FREE @interface MyViewController : NSObject <UIActionSheetDelegate, ADBannerViewDelegate> #else @interface MyViewController : NSObject <UIActionSheetDelegate> #endif { IBOutlet UILabel* myLabel; } - (IBAction) myAction:(id)sender; 

When I load MyViewController.xib in IB, it displays warnings in the Information window, for example, “MyLabel” output in “File Owner” is associated with “My View”, but “myLabel” is no longer defined in MyViewController. "

Is there a way to do this so as not to confuse IB?

I believe the other option is simply not #ifdef, but one definition for all builds. What happens if I build with my controller matching ADBannerViewDelegate (which requires iOS 4) and I deploy to iOS 3.2? If this works, there may be no problem ...

+1
source share
1 answer

I could not figure out how to get IB to understand the structure you are using (I tried to do this with the paid / free application that I did in the past). Here is how I solve my problem:

I did not use conditional compilation in my @interface definition. I just defined the class as usual, as if it were a paid, non-advertising version. Let me call it MyPaidViewController.

 @interface MyPaidViewController : UIViewController <UIActionSheetDelegate> { 

Then I created a subclass of MyPaidViewController, which was for the free version. Sort of:

 @interface MyFreeViewController : MyPaidViewController <ADBannerViewDelegate> { 

Since I usually needed to use a different xib for my free version than for my paid version (because I had to move things to make room for ads), I would just pay xib using MyPaidViewController, as File Owner and my free xib use MyFreeViewController as the owner of the file.

The Builder interface will also see IBOutlets from superclasses, so you can reference myLabel in your free xib.

Make sure MyPaidViewController is part of the free and paid build goals, but MyFreeViewController should only be part of the free build goal.

+2
source

Source: https://habr.com/ru/post/891839/


All Articles