Can't make files or folders inside main Xcode project folder - ios

I am trying to create swift files and groups inside my main Xcode project group but for some reason it doesn't let me do it. When selecting new file it creates it outside of the group selected, and if I try and create a new group inside, the option is just greyed out.
I have never had this issue before with Xcode 11 and earlier, is this a feature that has been removed? Do I now have to make a separate group and work outside the initial project group?
Hopefully the image below will help explain what I mean.
NOTE: I am running Xcode 12.2 on BigSur 11.0.1
Here is what happens when I try to drag and drop the folder into the products group.

I also created an iOS App titled "Products". Upon changing the name to something else (Product Manager) I was able to add files to the project

in the second step of creating the file, do you still have selected the right folder?
Or is there maybe an other folder selected?

Related

Cannot preview in this file - active scheme does not build this file : SwiftUI on Xcode 11 in CatalinaOS

I opened Landmark App using SwiftUI on Xcode 11 in macOS Catalina(10.15) and while opening the Canvas Editor for .swift files containing SwiftUI is showing
Cannot preview in this file - active scheme does not build this file
Try Again, Diagonistics option or restarting Xcode not solving the problem.
If this is a new project coming from a copied folder and inside an iCloud folder, just close Xcode and relaunch it. The sync was not yet done.
Select the Scheme that has the current file to Preview
You should go through Xcode and Apple SDKs Agreement and you can do it by running the following in terminal in mac:
sudo xcodebuild -license
After doing that reopen your project.
I experienced the same issue. All I did was to copy the "StartingPoint" folder out of the downloaded folder and relaunched the project. It worked!!!
I bumped into this too, following the Landmarks tutorial. When I created the 'CircleImage.swift' it was not letting me preview it, with the above error message.
You can see the current Scheme you're using by going to Product > Scheme. I've got macOS selected.
Clicking on the CircleImage.swift file loads it, and in the rightmost sidebar it shows the Attributes inspector. A few buttons to the left of that is "Show the File inspector".
There, you can see this file's chosen "Target Membership". My problem was that "Landmarks (macOS)" was not checked. Checking this immediately got the Preview working.
I imagine I could also have changed my Product's Scheme to iOS and it would have worked, as that was already checked.
I encountered the same error for some of my SwiftUI View files when trying to preview on Canvas. What fixed the issue was I copied the code within the current file, deleted the file, created a new SwiftUI View file under the same name and pasted the original code. Hope that helps!
Creating a new folder in Documents/Desktop and copying the files over also resolves the issue.
This problem happened to me when I copied a folder into my project with the "Create folder reference" option instead of the "Create groups" option.
The problem was solved when I deleted the folder from project and copied the folder again with the latter option.
I just upgraded to both Monterey 12.3, and Xcode 13.3, and boom ran into this issue. Things were fine before the upgrade. Nothing above helped.
Creating a new project does help. So the only thing I found is to create a new project, and just add the files from the old project to the new one. Yuk.
EDIT: I hadn't rebooted the computer (mac mini), after reboot things were fine again.
In the schemes I was able to select, it contained only one scheme. Reopening the folder in a folder that's not in the Downloads directory made live editing work for me
Restarting my PC worked for me.
The described issue happened to me after cloning a project via git (no iCloud syncing as described in another answer - so I definitely know that the sync itself was completely done).
Funny enough restarting Xcode did the trick.
Just closing and opening the project isn't enough.
I found that the file I was trying to preview was not listed in Target -> Build Phases -> Compile Sources. Once I manually added the file, Preview worked. I had drag and dropped a directory into the project, and for some reason Xcode had not added those files to that list.
Try About this mac -> Storage -> Manage -> Developer, Then delete Xcode cache from here then restart Xcode...This worked out for me
Make sure the file you are trying to preview is in your app (the folder with the same name as your project).
I was able to fix newly created files not previewing by moving the file into my project.
Another solution:
Make sure you select file type Swift UI instead of Swift File when you create the file.

No main.storyboard or ViewController.swift upon initialization of new project in Xcode?

I just got Xcode and I am trying to follow an online tutorial but in every single tutorial, when a new project is made (a single activity) app, the project comes with 2 files that I simply don't have by default! I can't figure out how to make a main.storyboard or ViewController.swift file by default upon creating a project.
The only files I have are AppDelegate.swift, SceneDelegate.swift, and ContentView.swift. I also have Assets.xcassets, LaunchScreen.storyboard, Info.plist, Preview Content directory, and Products directory.
Is this part of a new update or something? Or is there some way I can get those 2 files to create upon initialization?
I tried reinstalling, and have made multiple new projects - each time they lack those 2 crucial files, so any help would be appreciated.
In the latest Xcode, select Storyboard from the User Interface dropdown,
Older Xcode
Unselect Use SwiftUI at the following step,
On latest Xcode release you should change in the dropdown menu from "Swift UI" to "Storyboard"

How can I add file to project in Xcode 9?

I created a new project in xcode 9.
I want to add image file to project.
When I delete this file from desktop,
Image file appears in red?
But in project folder, I find this image file.
In Xcode 8 its working fine,
Any idea?
It is an Xcode9-beta (9M136h) bug. I don't know if it has been resolved in beta3 or not. Copy items if needed copies the file to your project directory but still links to the original file.
What I do is, after dragging the file to my project, I select the folder icon (see red circle in the image below) from File Inspector and point to the copied file in the project directory.
#pesch's approach works too. First copy the image to your project folder and then drag it to Xcode.
Xcode 9 allows to have folders in Xcode synced with folder in your Finder structure. I assume this is a bug since Xcode 9 is still in beta and you are "ticking" the Copy items if needed.
Try moving the image to your project folder yourself and drag it from there to Xcode.
This is what you would do to leave the Copy items if needed box unticked since you are doing it yourself.
It looks like a XCode 9 bug. If you check the Full Path of your image file in Identity and Type Tab, it would show the location of the deleted file, hence the deleted(red) color.
You can delete that reference and can use Add File To.. option to add the reference of (already) copied image from your source folder.
Although this is not resource related (images, etc). The issue that I'm currently facing with the Xcode 9.0 GM build is that adding the items to the project does not actually added them to my targets, although I selected them.
Step 1 - Add Files to Project
Add New Files and Select your targets
Step 2 - View Files in File Inspector
You can clearly see in the file inspector that it is not added to those targets accordingly.
Step 3 - [Fix] Add New Added File to Targets
To Fix this, just check the targets that the files should be added to and you should be good :)
I have seen this issue in Xcode 9.0 GM (build 9A235, same as the current release). It's intermittent; sometimes 'Copy items if needed' is honored, sometimes not.
In one case it seemed to be triggered by the presence of source control. I was working through an online tutorial where the provided project had no source control. Adding files here did honor the 'copy items' checkbox, but if I made the provided project a git repository first, adding files ignored the checkbox every time.

Xcode 6.3 New File Issue

I recently updated my Xcode to 6.3 stable version. When I try to add a new folder (Right Click ViewControllers -> Add Files to ... -> New Folder) it appears in blue color, instead of the default yellow color. And when i Right click the TestFolder -> New File, a blank file is created with out the option to choose a template for the file.
What's causing this problem? Thanks.
Yup, found the reason for this. By default, XCode was selecting "Create folder references" which was causing the problem. I selected the "Create groups" radio button instead as shown in the image below and I got the expected result. Cheers.
I believe this is a bug on xcode 6.3. It doesn't happen to the previous version. And if I may add, drag-dropping a folder to the project also produces a blue folder, inside are files which I can't properly call inside my classes. It doesn't even appear on the New File -> Cocoa Touch -> Subclass if you intend to subclass it.
Edit: Figured out the solution. Select "NEW GROUPS" on the dialog when adding. I didn't noticed it at first since previous xcodes have "NEW GROUPS" selected as default.
This error comes when you update Xcode to new version, When you add a new file or folder,from dragging or add from EDIT option,
the default selected option will be Create folder reference radio which add only reference to that file or folder but not the actual. This problem can be solve by selecting Create Group radio when adding file/folder.
This can solve your problem.
For people wondering how to get Copy Folder Dialog box , Just Drag and drop folders into XCode7 and the popup will appear where you can select either folder reference or create group option.
How do you get "New Folder"?
All I see is
I think this looks like a simple bug. Deinstall and Reinstall Xcode if restarting Xcode and your Mac does not help. Maybe that solves your problem.
Hope that helps :)
Since you are doing add folder it will create folder so that u will see blue and if you do add group you will see default yellow color.It does occurs in previous version too you mightn't have realized at that time

AppCode iOS application: Group folders not visible?

P.S. I am new to both AppCode and iOS
I added 2 groups menu and summary and added somefiles to it. I accidentally reverted some file hides these folders from project structure
But as you can see, these are available on filesystem
How do I get them back on project structure? I can't even search for them in AppCode
In AppCode right click on the pennyapp-ios group, click Add->Files... Choose your two folders and select "create groups for added folders."

Resources