简体   繁体   中英

Getting error after changing project folder name in XCode

When I created my project, I called it "Project1". Then, later I've changed it to "Project2" from the Xcode. I changed all "Project1" to "Project2", but now, when I compile my project, it looks for files in Project2/Project1/myFile.swift and I get the next error:

<unknown>:0: error: no such file or directory: '/Users/myusername/Copy/Projects/Project2/Project1/myFile.swift'

I need to make that it will look at

/Users/myusername/Copy/Projects/Project2/myFile.swift

without Project1 in the path.

How can I solve this problem? Also, I changed from Xcode Identity and Type section Location of my project.

  1. Change you folder name in you finder "Project1" to "Project2"

  2. Remove "myFile.swift" file from project (copy on Desktop)

  3. Restart Xcode. Copy "myFile.swift" in project select "Copy file to folder" hope this will help.

Renaming projects in xcode in one of the most annoying things in iOS development. I assume you want to rename your app. I faced this problem once and figured out a simple, clean way to do it.

  1. Go back to the point where everything worked.
  2. Open project in xcode and click on the project icon in the project structure( first file)
  3. Go to the info tab
  4. Search for Bundle Name . Most probably it will automatically be set to $(PRODUCT_NAME) which is a shell variable that will set your app name the same as the project name.
  5. Set it to whatever you want your app name to be
  6. Done

Note :

  • If you use custom URL Schemes this might produce an error when redirecting.
  • ALWAYS use git or some other SVN in your projects. This will come in handy in this kind of situations

Today I had the same problem when I renamed the folder containing the Xcode project and some parent folders of it.

In my case there where a .swift file shown with it's name in red in the list of files of Xcode (Navigator area). I think that this means that Xcode was not capable to find that file.

I selected that file (actually it's not a real file but a representation of it).

Then, in the File Inspector (Utility area), I clicked on the Folder icon and chose the file on Finder.

在此输入图像描述

This worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM