Modulation of iOS applications during build

I have my application screen as the following prototype: enter image description here Given this main screen, I have to design the application in such a way that each of the four functions must be plug-in during assembly. For instance,

If I set the macro as

#define FEATURE_1 0 

then on the main screen there will be only 3 tiles for the other three functions. In addition, files associated with function-1 must not be compiled as a result of .ipa.

When I developed these four modules, I saved all the classes independently. But the problem is that I have one storyboard containing the entire user interface. Now I need to separate the user interface and resources in such a way that, if any of the functions is disabled, the files associated with this function must be compiled.

What I tried : I read somewhere that creating each function as a static library would do my job, however I could not figure out how to enable / exclude the static library at build time. Also, this does not solve my problem of sharing views in a storyboard.

In particular, I have the following questions:

1) How can I copy certain files to my project and leave certain files depending on the macro as defined above? If possible, please direct me to a good way to do this.

2) How can I share my views on the storyboard? Is it possible to define several storyboards and include those required during assembly? Please guide.

+5
source share
4 answers

What I finished doing:

I have two functions: 1 and 2.

So, my requirements will be made by three types of assembly :

  • String with only function 1.
  • String with only function 2.
  • An assembly that has both functions 1 and 2.

So, I split the project files in Xcode as:

  • CommonModule - This group consists of the files required for both functions.
  • ModuleOne : This group consists of the files that are required for the function.
  • ModuleTwo : this group consists of files that are required for two functions.

The folder structure for which I ran for each module:

my folder structure

It is better to keep the project folder structure on disk, similar to the group structure of this project. This reduces confusion, and it becomes possible to add all files to a specific folder to a specific group. .

Now I have identified three goals that correspond to the three types of lines listed above.

  • TargetOne : Files in CommonModule and ModuleOne belong to this target.
  • TargetTwo : Files in CommonModule and ModuleTwo belong to this target.
  • TargetAll : Files from the CommonModule , ModuleOne and ModuleTwo groups are for this purpose.

Now in CommonModule I have a BuildConfig.h file with macros like:

 #define IncludeModuleOne 1 #define IncludeModuleTwo 1 

So, when building, select the appropriate target and accordingly switch the above switches to get the correct build.

Now in InitialViewController.m I checked the values โ€‹โ€‹of the switch, and depending on the values, I showed / hid the menu options for this particular function.

Thus, to summarize, I include only the required files in the assembly using several targets + configuration macros together

In the near future I will talk about a link to my sample project on GitHub. Hope this helps someone who has similar requirements. Thank you

+1
source

Answer for 1: you cannot use macros only.

Create several targets for different configurations, define the macros you need for each target and check the box to include only the files you need during the build.

+4
source

Although you can use the build system, in your case it will be easier for you to wrap the affected code in

 #if FEATURE_1 ... #endif 

To hide the views, you can use the code in the line

 #if !FEATURE_1 feature1View.hidden = YES; #endif 

depending on what exactly you are trying to achieve.

+2
source

Answer this question for 2. Use either a UICollectionView or use 4 views in XIB and use this method

 -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self){ // NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"--name of xibs--" owner:nil options:nil]; // self = [nibArray objectAtIndex:0]; } return self; } 

in nibArray, views will be saved

+1
source

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


All Articles