[英]Two Xcode projects, same target
I am working on version 2 of an iOS app. 我正在开发iOS应用程序的版本2。 Since I am rewriting it in Swift, I started a new Xcode project.
自从我用Swift重写它以来,我开始了一个新的Xcode项目。 Even though the target names are the same, I get two different apps on my device or simulator, so they don't share data and preferences, etc.
即使目标名称相同,我在设备或模拟器上还是得到了两个不同的应用程序,因此它们不会共享数据和首选项等。
Is it possible to have two different projects share the same target? 是否可以使两个不同的项目共享相同的目标? Or should I brute-force replace everything (after a triple backup :) in the original project folder?
还是应该用蛮力替换原始项目文件夹中的所有内容(三次备份后:)?
No, it's not possible. 不,不可能。 Better update original project.
更好地更新原始项目。
I spend a couple of days and many tries to get this to work, and am outlining below the steps I took. 我花了几天时间,尝试了很多方法来使它正常工作,并概述了我所采取的步骤。 Hopefully this can be useful to others as well.
希望这对其他人也有用。
Background: To learn Swift and also modernize my app, I decided to completely re-write it, using all the goodies of Swift and the newer iOS APIs. 背景:为了学习Swift并使我的应用程序现代化,我决定使用Swift的所有优点和更新的iOS API完全重新编写它。 Instead of slowly converting one class from Objective C to Swift, as it is described in many tutorials, I just started from scratch.
我没有像许多教程中所描述的那样将一个类从Objective C缓慢地转换为Swift,而是从头开始。 So I made a new project, with the same name of the target, added some basic functionality, and ran it on the simulator.
因此,我创建了一个与目标名称相同的新项目,添加了一些基本功能,并在模拟器上运行了该项目。 To my surprise, or maybe not, a new app was created, so I had two apps, one written in Objective C, and the new one in Swift.
令我惊讶的是,也许没有,我创建了一个新应用程序,所以我有两个应用程序,一个是用Objective C编写的,另一个是用Swift编写的。 Since my app uses Core Data, they need to be the same, otherwise the user will lose all his/her data when upgrading.
由于我的应用使用核心数据,因此它们必须相同,否则用户在升级时会丢失所有数据。 So with a lot of trial and error I was finally able to get this to work, here are the steps I used:
因此,经过大量的试验和错误,我终于能够使它起作用,这是我使用的步骤:
Disclaimer: use at your own risk - make sure to have backups so you can always revert. 免责声明:使用风险自负-确保备份,以便您始终可以还原。
Optional if you want to have two different projects: 如果要具有两个不同的项目,则为可选:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.