Does anyone know if it is possible to open a C++ file outside of an XCode project and still be able to run it? - xcode

When you open a .cpp file with XCode, you can edit it and everything, but the run button doesn't show. You can convert it to a workspace, but even then, the run button is greyed out, even if you create a new scheme (since you can't create new targets in a workspace). I have also tried File > New > Project, but it doesn't transfer the files that are already in the workspace into the project. Help!

Related

How to create a new workspace file in Xcode?

I was moving around my Xcode folder project and I have accidentally deleted the .xcworkspace file (the white one). Is it possible to generate a new one?
Like others have suggested, source control would be a great idea if you're not using it already, to protect you in this precise scenario. Github is a great place to start for that.
To create a new Xcode workspace
In the Xcode menu, click File > New > Workspace, then follow the prompts.
Once that's done, you'll have an empty Workspace, and you can drag whichever .xcodeproj files in that you wish to the sidebar to add them to the workspace.

Codeblocks adding files to current project doesn't work

What I mean by this is that usually in codeblocks when you create a new file while you have a project open asks you to add it to the project, and when you do it'll be tied to it so when you open the project file it will have the files with it, but this doesn't work for some reason, also right click in management doesn't work, just the whole management panel seems to be broken.
TL;DR: Codeblocks doesn't add newly created files to current open project file.
I get all sorts of errors and crashes in CodeBlocks... I'd create the file you want, then manually add it to the project folder (outside of CodeBlocks with file explorer/Finder/terminal) you want it in and refresh...

In Xcode how do I create a new workspace and add 1 project to it so that I can see the project and its files?

In Xcode how do I create a new workspace and add 1 project to it so that I can see the project and its files?
If I just drag in the project, all I can see is the project it cannot be expanded, I cannot see the files. Also, is there anyway to copy over existing schemes from the project so that they can be used in the workspace?
First choose file > new > Workspace...
Then, you must first, and this is important, you must first close the project that you want to drag in. Than drag in the .xcodeproj file from the finder to your new workspace. Then it will appear properly and expand to show all of its files and your schemes will be available.
Although the accepted answer is correct, there is an alternate way to accomplish the same thing, and it is arguably easier/more straightforward. You can just open up the project in Xcode and click File -> Save as Workspace...
Bam! You now have a workspace with 1 project in it, as requested.
Just FYI, 2020, Apple recently added a thing,
make your workspace, exit it and
make your new project. in fact when you enter the name to save the project,
they added this option:
just select the workspace you wish to add it to.
Besides all above solutions you can use this alternative. Let's say you have a workspace and a project that you want to add to that workspace.
Close your project.
Open your workspace.
Option + Click in the Project navigator. Make sure you are clicking on an empty area, not on the existing files or folders.
In the context menu, select "Add files to your workspace...".
Finally select your project xcodeproj file on you disk.
Have a nice project 😉,
Add project into workspace
As alternative
- Close a project that you are going to add to a workspace
- Open Project Navigator -> Right click -> Add Files to "<workspace_name>"...

xcodeproj file is missing

I have folder where i store all my projects. I have problem with one of them.
All projects except this have projectname.xcodeproj file.
When i open Xcode i see this project - it has icon with white background (other have blue background). I can open it, build and run.
I can't find this .xcodeproj file - so i can't run pod init in terminal for this folder. I See error "No xcode project found, please specify one".
I don't use git. Searching for this file had no results. What else can i do?
I think you may have changed the path for the specific project you're experiencing problems with. Try to create another project and just copy/paste the files from the old project into the new one and reference the new project.

How to refresh Project Navigator content in Xcode?

I'm not able to refresh file list in Project Navigator. There is no refresh button, and I don't think restarting Xcode should be the solution.
How do you see files that you add externally? I'm on Mac.
How do you see files that you add externally?
Files cannot be added externally. Dumping a source file into the project directory does not add it to the project. To add a file you must add it to the project from within Xcode.
If you have a bunch of files that you need to add then in the Add File dialog you can just select all the files you want at once and add them, without having to repeatedly open the Add File dialog. Just use control clicking to select multiple files.
Close and reopen the project, if necessary.
This may be required if you are using folder references (as one example). In that case, touching the directory might work to refresh what Xcode displays.
For a single file, you can open the external file in Xcode and cmd+s to save it, it will be refreshed in Xcode.
Also, for the quick way you can just chose the external folder in Xcode and cmd+s, it will refresh all your external file in this folder.
File > Add files to "Runner" 👍
I don't think you can refresh the Project navigator to detect files that have been modified outside of Xcode, and that instead you need to manually add or delete files from the Project navigator with "right-click" / two-finger tap.
Some other solutions suggested:
File > Add Files to "Runner"... but that doesn't delete files
Open and close Xcode, but that's not practical. It also did not work for me.
Use cmd+s, but Xcode does not detect files which need to be saved. And so, that also did not work for me.
You can just press "Command + B", for refresh your project in xcode

Resources