Ok, I have an iPhone project that utilizes the camera.
好的,我有一个利用相机的iPhone项目。
I'm trying to utilize 80% of the same code for an iPad version of this project, however, I have to change some values as the camera quality in the latter device is messing with some parameters which I used as criteria for the first device.
我正在尝试将80%的相同代码用于此项目的iPad版本,但是,我必须更改一些值,因为后一个设备中的相机质量正在弄乱我用作第一个设备的标准的一些参数。
So what I did was: I duplicated the iPhone project and had two targets in total, in the same project, the first one - for the iPhone (the original), and the second for the iPad.
所以我做的是:我复制了iPhone项目,总共有两个目标,在同一个项目中,第一个 - 用于iPhone(原始),第二个用于iPad。
When I clicked on the second target and added a comment on some .m file, the same comment appeared in the same .m file in the iPhone version's file too.
当我点击第二个目标并在某个.m文件中添加注释时,同样的注释也出现在iPhone版本文件的同一个.m文件中。
I don't want that - as you can see, I want a separation. I want to use the iPhone project as a base to modify the code of the iPad project. But how do I do this ? If the comment appeared in the iPhone .m too then obviously that means there is no distinction , and that whatever I do in the iPad .m will mess up the other .m ?
我不想那样 - 你可以看到,我想要分离。我想用iPhone项目作为修改iPad项目代码的基础。但是我该怎么做?如果评论出现在iPhone .m那么显然那意味着没有区别,而且无论我在iPad .m做什么都会搞砸另一个.m?
5 个解决方案
#1
3
it looks like your two projects are sharing the same files. If you want to keep them separate, just duplicate the source files and add them back to the projects individually.
看起来你的两个项目共享相同的文件。如果要将它们分开,只需复制源文件并将它们单独添加回项目。
#2
1
I'd create a universal app. That way you can share all of your code between the two devices in a single project. Then you can simply separate logic for each device type into different files. So for example, have ViewControllerA
for both device, and ViewControllerA_iPhone
and ViewControllerA_iPad
for the each separate device.
我会创建一个通用应用程序。这样,您就可以在一个项目*享两个设备之间的所有代码。然后,您可以简单地将每种设备类型的逻辑分成不同的文件。例如,对于每个设备都有ViewControllerA,对于每个单独的设备都有ViewControllerA_iPhone和ViewControllerA_iPad。
#3
1
Possible duplicate: Conditional Compilation between ipad and iphone
可能重复:ipad和iphone之间的条件编译
I think you don't need a second implementation file, you just need to compile for a different device or check which one you are on at runtime and adjust accordingly.
我认为您不需要第二个实现文件,您只需编译一个不同的设备或检查您在运行时使用的是哪个并进行相应调整。
#4
1
I think don't need to copy the entire project. You can just copy the necessary files only and create logical groups for iPhone and iPad. Check the device type into appdelegate class if it is iPad then call iPad related class else iPhone. Hope it will help you.
我认为不需要复制整个项目。您只需复制必要的文件并为iPhone和iPad创建逻辑组。检查设备类型是否为appdelegate类,如果是iPad,则调用iPad相关的其他类iPhone。希望它会对你有所帮助。
#5
0
it sounds to me like you need to 'extend' the functionality of the original to incorporate the new.
听起来像你需要'扩展'原件的功能以合并新的。
Would it not be easiest to create the 'interface' and then an base form of the class (maybe make it abstract), that implements all the methods, but leaves those that may have special needs (just have them throw an error as basic method functionality)
创建'接口'然后是类的基本形式(可能使它成为抽象)并不是最简单的,它实现了所有方法,但留下了可能有特殊需求的那些(只是让它们抛出错误作为基本方法)功能)
Then for the 2 projects you can extend the abstract class and overide the methods adding in the functionality that you require.
然后,对于2个项目,您可以扩展抽象类并覆盖方法,添加您需要的功能。
The beauty is that if there is an error condition in the overidden methods you can just call the 'superclass' abstract method and throw out the error message, you may decide that the super class method should take a string input variable to enable you to use a customised message taged onto the end of the one in the abstract class.
美妙之处在于,如果在覆盖方法中存在错误条件,您只需调用“超类”抽象方法并抛出错误消息,您可以决定超类方法应该采用字符串输入变量以使您能够使用一个自定义的消息,它被贴在抽象类的一个结尾处。
David
#1
3
it looks like your two projects are sharing the same files. If you want to keep them separate, just duplicate the source files and add them back to the projects individually.
看起来你的两个项目共享相同的文件。如果要将它们分开,只需复制源文件并将它们单独添加回项目。
#2
1
I'd create a universal app. That way you can share all of your code between the two devices in a single project. Then you can simply separate logic for each device type into different files. So for example, have ViewControllerA
for both device, and ViewControllerA_iPhone
and ViewControllerA_iPad
for the each separate device.
我会创建一个通用应用程序。这样,您就可以在一个项目*享两个设备之间的所有代码。然后,您可以简单地将每种设备类型的逻辑分成不同的文件。例如,对于每个设备都有ViewControllerA,对于每个单独的设备都有ViewControllerA_iPhone和ViewControllerA_iPad。
#3
1
Possible duplicate: Conditional Compilation between ipad and iphone
可能重复:ipad和iphone之间的条件编译
I think you don't need a second implementation file, you just need to compile for a different device or check which one you are on at runtime and adjust accordingly.
我认为您不需要第二个实现文件,您只需编译一个不同的设备或检查您在运行时使用的是哪个并进行相应调整。
#4
1
I think don't need to copy the entire project. You can just copy the necessary files only and create logical groups for iPhone and iPad. Check the device type into appdelegate class if it is iPad then call iPad related class else iPhone. Hope it will help you.
我认为不需要复制整个项目。您只需复制必要的文件并为iPhone和iPad创建逻辑组。检查设备类型是否为appdelegate类,如果是iPad,则调用iPad相关的其他类iPhone。希望它会对你有所帮助。
#5
0
it sounds to me like you need to 'extend' the functionality of the original to incorporate the new.
听起来像你需要'扩展'原件的功能以合并新的。
Would it not be easiest to create the 'interface' and then an base form of the class (maybe make it abstract), that implements all the methods, but leaves those that may have special needs (just have them throw an error as basic method functionality)
创建'接口'然后是类的基本形式(可能使它成为抽象)并不是最简单的,它实现了所有方法,但留下了可能有特殊需求的那些(只是让它们抛出错误作为基本方法)功能)
Then for the 2 projects you can extend the abstract class and overide the methods adding in the functionality that you require.
然后,对于2个项目,您可以扩展抽象类并覆盖方法,添加您需要的功能。
The beauty is that if there is an error condition in the overidden methods you can just call the 'superclass' abstract method and throw out the error message, you may decide that the super class method should take a string input variable to enable you to use a customised message taged onto the end of the one in the abstract class.
美妙之处在于,如果在覆盖方法中存在错误条件,您只需调用“超类”抽象方法并抛出错误消息,您可以决定超类方法应该采用字符串输入变量以使您能够使用一个自定义的消息,它被贴在抽象类的一个结尾处。
David