Add Xcode Target - ios

I'm not sure why this is so difficult/hard to find any documentation for but I'm trying to add an initial target to a scheme for my workspace.
I created a new workspace, added some files, made a new scheme named "Default" but when I try to use it I get the error code "Scheme Default is not currently configured for the build action."
I can't find any docs on how to add a target. Target is grayed out in File > New > Target and when I try to add one with the "+" button in the "Edit Scheme" menu it just shows an empty list with a search option that is obviously going to be blank.
I've heard that Xcode is a nightmare to work with but I can't understand why I can't just add a target.

You can only add a new Target to an existing Project. If you start with a Workspace, it has no projects in it.
Go to File -> New and select Project...
Select the type of Project (such as Single View App)
Give your project a Name, and specify options (Team, Organization, Language, etc)
Select Next, and you're presented with a Where to Create window
At the bottom you should see an option for Add To:
From that drop-down, select your current Workspace
In this image, I already have HelloCpp project open, and I have wkplace Workspace open.
If I choose wkplace, this new project will be added to my Workspace and the Project and Target will be automatically added.
Edit:
Here is the full step-by-step.
New empty Workspace - named WorkSpace1:
Selected File -> New -> Project... then Selected Single View App, clicked Next:
Entered MyNewApp as the Product Name and clicked Next:
Selected WorkSpace1 from the Add To: drop-down, and clicked Create:
And I'm taken back to my WorkSpace1 window, with the new Project and Target showing:

Related

Is there a way to hide bundle id and apple developer team from public GitHub projects?

I want to make my project open source but don’t really like the idea of my apple developer name and app bundle id being public. Is there a way I can hide it?
Ive not made an open source project before so open to all suggestions.
By default, Xcode stores your product bundle identifier and your development team identifier as build settings in your xcodeproj, along with all the other details of your project structure.
You can tell Xcode to load build settings from a file with the suffix xcconfig. By moving just those settings to an xcconfig file, and telling Git to ignore that file, you can publish your repo without publishing those settings.
Follow these steps to move those two settings out of your xcodeproj and into an xcconfig file:
Add a new file to your project. Use the ‘Configuration Setting File’ template:
Name the file project.xcconfig. Add it to the top-level group (which is your project itself) and don't add it to any targets.
Xcode should open project.xcconfig automatically. If it doesn't, click it in the project navigator to open it.
Open the project editor in a separate editor pane. You can create a separate editor pane by clicking this button in the top-right corner of the editor:
Then click on your project itself (the top-level group) in the project navigator to open the project editor:
Make sure the project itself is selected in the project editor's outline:
In the Configurations section, click the chevron next to “Debug” to show its child, which is the project itself. Then, on the project row, click the popup menu in the “Based on Configuration File” row and choose “project”. Do the same for the “Release”. When you're done, it should look like this:
Click on your target (your app) in the project editor's target list. Then click the “Build Settings” tab. Then click “All” and “Levels”.
In the search field at the top right, type product_bundle_identifier. Double-click the green box in the table that shows your product bundle identifier:
Xcode opens a popover where you can edit the product bundle identifier. Press ⌘C to copy the identifier to the clipboard.
In the other editor pane, which should still be editing project.xcconfig, add a line at the end with the text PRODUCT_BUNDLE_IDENTIFIER = and paste in the identifier using ⌘V.
Click on the “Product Bundle Identifier” row label in the build settings editor to select the row. Press the delete key.
Xcode removes the setting from your .xcodeproj, leaving it only in the project.xcconfig file. If you deselect the row in the build settings editor, it looks like this:
You can see that Xcode is now reading the setting from project.xcconfig.
Repeat the process for the “Development Team” setting. Search the build settings for development_team. Copy its value to project.xcconfig, using the setting key DEVELOPMENT_TEAM. Then select the “Development Team” row in the build settings editor and press the delete key to remove the setting from your .xcodeproj. Your project.xcconfig should now look like this:
//
// project.xcconfig
// HideDevInfo
//
// Created by Rob Mayoff on 1/24/23.
//
// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974
PRODUCT_BUNDLE_IDENTIFIER = com.dqd.HideDevInfo
DEVELOPMENT_TEAM = SECRET123X
Clean your build folder (from the menu bar, choose Product > Clean Build Folder). Build and run your app. Make sure it still works.
Edit your .gitignore file. (If you don't already have one, create a new empty file at the top of your Git work tree.) Add a line that says project.xcconfig.
Commit your changes.
Please note that if this is not your first commit in the Git repository, your bundle identifier and your team identifier are still visible in the older commits. You may want to all your commits down to a single commit to remove them. There are ways to edit your commit history to remove those settings from all prior commits, but you'll need to post a separate question if you want to try that.

Multiple Targets in Xcode: "File not found"

I am having a single project file. Then I created another target for a "Lite" version. I changed the bundle ID and product name for each target and am able to continue working this way.
But when I added a new custom class to the project, I try to use the class in existing VC by #import "NewClass.h" but it only works on one target, on the Lite target, it says:
File not found
Why is this and how to solve it?
While adding any new file and if you are working on multiple targets and you want that file in both the targets then you need to check both the targets while adding file
Check screenshot
You need to add the file to both the Target, so it can be accessed.
Click on the file you have added and then go to the Utilities Area in the right and click on File Inspector. You will have section called 'Target Membership', please select the target from the list of Targets.
Alternatively approach :
Select the Target in which you are getting error then got to Build Phases -> Compile Sources and make sure the file is present there.
If you forgot to add a target when you creating a file, you can add later by selecting the file in project navigator and then check/uncheck the target(s) in the File Inspector (on the right)

How to change the organization name on an existing Xcode project

I created a once off Xcode project but entered the organisation name in incorrectly. How can I change it?
There are two things you will need to do. With the project or target selected, you can update the "Organization" field in the "Project Document" section of the "Utilities" panel (usually on the right).
Next, for an existing source files, you will need to perform a search/replace to update the header comments. Only new files will automatically get the new organization name.
Click on target -> click show the file inspector -> organization name text field edit organization name
If you need to edit Project name
1- select you'r project then press Enter edit name
2- show rename project content items
3- click rename
4- build your project
Note : If you use pod should change Target name in podfile then pod
install ، You will find that he has created a new file
newTarget.xcworkspace

Dependencies in Xcode Workspaces

I'm trying to set up a workspace so that different projects can access the same files.
In Project A, I did a "Save As Workspace..."
Then I created Project B in the new workspace.
I can now see both in the Project Navigator.
So say I have a category that was in Project A called "UIView+Awesome" that I want to use in Project B, how do I set up that dependency?
In a view controller of Project B I get this:
#import "UIView+Awesome.h" //UIView+Awesome.h file not found
Here is how to solve it.
Click on the target that's importing UIView+Awesome.h.
Click on Build Settings.
Enter Header Search Paths into the search box.
Double click on the value cell.
Click the + sign.
Set the path to the project you're referring. Let's say it's called Awesomelib. The path is relative to the root of the referring project (the project that's using Awesomelib). For example: ../Awesomelib/src/headers/ or wherever it is that the .h file lives.
Click Done.
Clean and then Build.

Rename xcode project

In all of my stupidity I've notice I misspelled my own project. I'm honestly scared to rename it in Mac due to certain filepaths referencing folders that now do not exist. Is there an easy way to rename a project?
Try refactoring, It should work fine, if it doesn't refactoring creates a snapshot instantly.
In Xcode, go to the navigator panel and select the target:
Go to the inspector panel (on the far right) and select the File Inspector icon. You can change the project name here. (You will get a pop-up dialogue to confirm the changes.)
so try it out, if it blows up restore, and create a new project, and migrate to the new one slowly (as #troop231) mentioned.
good luck!
source
I've posted this as an answer elsewhere, but this works like it should...
This is a four step change. And is a real pain
Step 0 - Backup your existing project
Quit Xcode
Right click the master folder containing the project file and the assets, select archive
This will create you an archive of the OLD project
Open the OLD project in Xcode again
Step 1 - Rename the project.
Click on the project you want to rename in the “project navigator” on the left of the Xcode view.
On the right select the “file inspector” and the OLD name of your project should be in there under “Identity and Type”, change it to the new name.
A drop down appears, with a “rename” ok box
Click rename.
Step 2 - Rename the Scheme
In the top bar, just by the “Stop” button, is the scheme for your OLD product, click this then “manage schemes”
Click on the OLD name in the scheme, and it will become editable, change the name. (If you click it twice, you go into the editor (which you don’t want) click the manage schemes button to get back again)
Step 3 - Rename the folder with your assets
Quit out of Xcode
In the correctly named master folder, there is your newly named xcodeproj file with the the wrongly named OLD assets folder. Rename the OLD folder to your new name
Reopen the project and you get a warning “The folder OLD does not exist”, dismiss the warning
On the left in the “project navigator” click the top level OLD folder name.
On the right in the “file navigator” under “Identity and type” you will see the “Name” entry, change this from the OLD to the new name
Just under this is the “location” entry, just below that is a folder symbol with the OLD name. click this and chose the newly renamed folder
Step 4 - Rename the Build plist data
Click on the project in the “project inspector” on the left, in the centre panel select “Build Settings”
in this section search for plist
Under packaging, you will see Info.plist, and Product bundle identifier.
In Info.plist rename the OLD entry
In the Product Identifier and rename the OLD entry
FINALLY you are done and can rebuild (Apple-key+shift+k clean, Apple-Key+b then build)
I've found myself in these situations many times and this is what has helped me without any issues. https://github.com/shabbirh/Xcode-Project-Renamer
There are many options out there, a few works, others don't.
Follow this and you can enjoy a cold or hot drink instead of fighting with the Xcode rename process.
Install dependency
Run the command
gem install xcode-project-renamer
And then lookup for the ProjectToBeRenamed.xcodeproj file
cd yourParentProject/
xcode-project-renamer ProjectToBeRenamed NewProjectName
# Verbose information here.
# at the end you would see
Done.
I hope this helps others.
If you've just started it's easiest to just create a new project with the correct name, then delete the old one. We (I) do this all the time.
To change Project name go through this scenario.
Select target
Select Build Settings
Search product name here
Then Change the new App name here
please note that the XCODE project name will not change but when you run the App name will be change

Resources