I haven’t tried this before but wanted to know how it happens. Suppose I have an Xcode file for my project called ‘Project A’. Now I want to make another project with the same features as that of ‘Project A’ for a project called ‘project B’. But for ‘project B’, I don’t want to make a different Xcode file but rather want to incorporate the changes in ‘project A’ itself so that when I run the same project, I’ll be able to run project A or project B as per my need. How can I achieve this…?
Click on your project, Goto General > Targets.
Right click on your project Target and select Duplicate.
You will get to choose between iPad and continue to duplicate for iPhone.
Going ahead in each new/existing file, you can choose which target it belongs to and keep doing your development. If you exclude the file from an target, it will not contribute to that app's size.
You can also keep your future files in both Targets depending on your needs.
Related
I cannot believe how hard this is. Perhaps because the word 'workspace' is overloaded by Apple and perhaps because the UI keeps changing every version. For a newbie to iOS, Xcode and Apple it's a nightmare.
I have Xcode 12
I have created a project.
I used File/save as
workspace to create a workspace to (eventually) hold multiple
projects.
Gave it a name.
I have another already created project (a
static library) that I would like to add to this workspace.
I cannot for the life of me figure out how to do it. I see things for
previous Xcode versions but those UI options are not present in 12.
In the end I want to have a workspace where I have a demo project that uses the static library project for Bluetooth LE communications. I will be spending 90% of my time developing the BT library so I want to be able to access the source of both projects.
By the way, I am not using Storyboards. Not sure if that makes a difference, but just in case!
Thanks for any help
You can do this by
Close the project to add in Xcode
Drag the existing.xcodeproj file (one you closed) from Finder to Xcode and drop it next to existing sources/projects in the workspace
Xcode settings are often painful for even seasoned developers. And every update seems to break something.
As far as I can tell it just doesn't seem possible.
The only option seems to be to create the workspace in XCode 11 add the projects there then open in XCode 12
If you already have a Workspace (i.e. a .xcworkspace file) ready to go, all you need to do is:
Close your project
Open your Workspace
Go to File > Add Files to "<your_workspace_name>"...
Select your existing project
Xcode will duplicate the references to your files, so you manually have to go to the Project navigator (shortcut: ⌘ + 1), select the duplicated references (they'll be at your Workspace's root) and delete them (select Remove Reference, not Move to Trash)
Enjoy your Workspace!
For good measure, select your scheme (most times it'll become available immediately, but sometimes you'll need to restart Xcode), build, and run your project to verify that everything went well.
Verified in Xcode 13.
I wanted to add a WatchKit Extension (with SwiftUI supported on iOS13+) to my existing app (target iOS12) while keeping both codebase separated (two repos).
How can I separate the WatchKit Extension code from the Mobile One?
Will my Watch App with SwiftUI only work for users with WatchOS 6 and iOS13 without affecting the existing users with iOS12?
How about the app binary size increase?
Thanks for reading!
I am not sure if there is a simpler solution, but this one should work:
Separation of both apps:
If you open in Xcode the Source Control navigator, you see that Branches, Tags and Remotes belong to a main entry in the Project navigator, i.e. to a Xcode project. So in order to have separate repos, you need separate Xcode projects to which you can assign separate repos.
You can however have multiple projects in one workspace, so that all files are available in this workspace.
To have one standalone app, and one app with a watch extension, just setup a workspace with your standalone app, and add another new project. This new project needs all files of the original app plus the watch extension.
Since you need files from one project also in the other, you could drag them from one project to the new one, but then they will be copied (a green + badge is shown during dragging). Usually this is not what you want, since you usually don’t want to maintain two copies separately. Instead, you can show such a file in the finder, and then drag it from the finder to the new project. In this case, you have the option only to copy the reference.
Independence of both apps:
Since you have two separate projects, you can set the deployment target in the target’s build settings as required.
Size:
Each project will get separate products, the standalone app only an xxx.app, and the new project xxx.app, Watch.app, and Watch Extension.appex. So there should be no overhead.
EDIT (due to the comment of Ouadie in his question):
I am not sure if I understand your problem:
With the procedure above, you get a single workspace with two separate projects that share part of the files.
The „mobile project“ is the same as you use right now. It has only a single target (despite of test targets) that is built exclusively with the sources required. It has thus the same size as now.
The „watch project“ is new. It has 3 targets, the „mobile“ target, the Watch target, and the Watch Extension target (despite of test targets). It is built with the shared sources, and the additional watch extension sources. Its size is thus larger, but the increase depends of course on your sources.
Since you have 2 repos, the projects are decoupled, but both repos share some files. If you want to decouple them completely, you could copy the files from your current project to your new project (instead of copying only references), but then you had to maintain 2 copies.
I hope this helps!
I have my own framework which I've made. I use this framework in another project I made. That is, after building my framework, Dragged the Product, .framework to Embedded Binaries of project.
However, I've to continuously make changes to the framework. So the process of dragging and dropping again and again is a lot of work. How to conquer this ?
Can someone tell the exact steps even if it means including the project as well ?
Copy the framework Project to your project folder.
Open your Project in xcode.
Right click on the Project File on left side of xcode and click on option "Add file to Project Name" and then select the framework project here.
Delete the Product .framework available in the embedded libraries and add the framework product properly.
So your goal is to 'deploy' changes made to .framework to all the projects you've already embedded it in previously. Here is one approach to it.
Create [myFramework]Targets.txt file where you'll be putting all the locations (directories) of your framework in different projects, line by line. It will have something like this:
~/Path/to/project/A/Frameworks
~/Path/to/project/B/Frameworks
~/Path/to/project/C/Frameworks
Create deploy_framework.sh file with script that will replace your framework everywhere you need. I'm definitely not the one you can call a Bash expert, by here is what it probably looks like:
for destination in $(<[myFramework]Targets.txt); do /bin/cp -rf /Path/to/updated/[myFramework].framework "$destination"; done
Now, whenever you're done with your framework changes, just run deploy_framework.sh from Terminal. Assuming your Xcode projects have existing reference to .framework and you didn't change its name, it should work.
NOTE: You might still need to do Clean+Build for your projects to compile with updated framework. I believe you can also tweak project settings to 'cache' builds less aggressively.
Let me know if it works for you, we might need to adjust script a bit, since I never tested it.
I have a project for iOS, and another project for MacOS.
Now I want to combine them (I want to be able to see them both at once, to be able to share code, and to choose which one to build at the scheme).
I know I can go to one of the projects and create there a new target, but isn't is possible to copy a target from one project to another?
It would be a lot simpler, and may save some errors that might occur when creating a new target..
Edit: and what's considered to be better?
one project to hold 2 targets (iOS/MacOS) ? or 2 projects with 1 target each?
You can create a Xcode Workspace (.xcworkspace) under File -> New and then simply drag in both your Xcode projects under the same workspace.
I have an iPhone app that needs to be physically cleaned to prevent the following build error:
This is what I have in the Navigator:
And this is what I have in the Localization section of Build Settings:
It works, but I'm not sure this ever worked the way it was supposed to; it was written several (like 4) years ago. Now, I am trying to clean it up so I can convert it to a universal app (first I need to make sure it works as designed before making any drastic changes.)
Can someone please point me in the right direction for cleaning this up? (I.e. what files to delete, or ?)
Here is what probably happen in that project:
This xx.lproj file is a legacy. You should be able to find it in Finder but not in a Project Navigator. Like this:
This is only the internal structure of xcode so just remove references from project navigator for all this ``xx.lproj` groups without removing files from project and you'll be fine.
If the app stop building you may need to re-add this files to your target, to do this just select a "parent" storyboard and go to "File Inspector" (first tab on Utilities panel) and select desired target.