Inadvertently see the clever God article, feel very excited, this article just solves the company's current project pain point.
Read the following key paragraph, not very clear, so I did the experiment to share to the people.
"Each of our course's resource files have the same file name, such as the home page background is called Homebackgroundbg.png, because each course background is different, so we in the project, each curriculum target, through the modification Copy Bundle Resources
, So that they are configured with different (but identically named) Homebackgroundbg.png. The benefit is that, at the logic level of the code, we don't have to deal with the differences in resource files between courses at all. The variance of the resource file is ensured by the configuration file. ”
My Project code address: Https://github.com/Dast1990/MultiTargetTest
Command-line Download method: Git clone [email protected]:D Ast1990/multitargettest.git
Clone target method and related knowledge see "http://www.jianshu.com/p/83b6e781eb51"
Note: The different target can only refer to the file under the corresponding directory, if the build phases more references, select the point-number to delete the extra reference, otherwise the compilation will not pass.
Select Multitargettest scheme and run, Output 1, display the corresponding picture in directory 1;
Select Multitargettianjin scheme and run, Output 2, display the corresponding picture in Directory 2;
As a result, it also validates the paragraph in the ingenious God article.
The project uses xcode8.2.1,swift3.0, the main code is as follows:
viewcontroller.swift// multitargettest//// Created by Ma on 2017/3/8.// Copyright 2017 Huatu. All rights Reserved.//import Uikitclass Viewcontroller:uiviewcontroller { override func Viewdidload () { Super.viewdidload () print (CONST.LNUM1) View.addsubview (GIMGV) gimgv.center = View.center Gimgv.bounds = Cgrect.init (x:0, y:0, width:100, height:100) } private lazy var Gimgv:uiimageview = { Let LIMGV = Uiimageview () limgv.image = Uiimage.init (named: "Clannad") return LIMGV } ()}
Directory 1 under:
const.swift// multitargettest//// Created by Ma on 2017/3/8.// Copyright 2017 Huatu. All rights Reserved.//import Uikitclass Const:nsobject {static Let Lnum1:int = 1}
Directory 2 under:
const.swift// multitargettest//// Created by Ma on 2017/3/8.// Copyright 2017 Huatu. All rights Reserved.//import Uikitclass Const:nsobject {static Let Lnum1:int = 2}
"Using multiple target to build a large number of similar apps", Tang Qiao Great God Theory verification (with project code address)