BLACK FRIDAY SALE: Save big on all my Swift books and bundles! >>

Help needed: Xcode won't build my project because it can't find a file that I purposely deleted. How do I fix it?

Forums > Swift

While attempting to incorporate sound in my project for the first time, I dragged the desired file from my Downloads folder inside of Finder, directly into my project navigator without making sure it would copy as needed. This led to not being able to find the file at runtime, so I deleted it so I could try again.

To be completely clear, I deleted it by selecting it in the project navigator, then pressing command + delete. When prompted, I opted to move it to the trash.

Now, when I try and build (yes, I mean build, not run) my project, Xcode throws an error saying that file can’t be found, and it points back to my Downloads folder in Finder. This file is no longer in my project, nor is it represented in the project navigator. What can I do to fix this?

   

@DarkhorseStudios - try and clean build the project Xcode -> Product -> Clean Build Folder

   

I've tried that already with no luck. Any other ideas?

   

Ok - go to project root in Project Navigator and then select "build phases." There's a "Compile Sources" section. if the file is listed there remove it.

   

Okay, thanks. Can you be a little more clear though, please? I’m completely-blind and tracking this down is proving to be very difficult. First, are should this “Build Phases” option be in the project editor, once I’ve selected the project root in my project navigator? Second, in the project editor, I’m finding “Build Settings”, rather than phases. With that selected, there’s a table with a ton of options, none of which seem to be “Compile sources”. Does it sound like I’m at least looking in the right place?

   

To access the build phases for a target,

  1. Open the project editor by selecting the project file on the left side of the project window.
  2. Select the target on the left side of the project editor.
  3. Click the Build Phases button at the top of the project editor.

An iOS app target for a newly created project has the following build phases:

  • Target Dependencies
  • Run Build Tool Plugins
  • Compile Sources
  • Link Binary with Libraries
  • Copy Bundle Resources

The two most interesting build phases for your situation are the Compile Sources and Copy Bundle Resources build phases.

I noticed you asked another question about not being able to play a sound file. The sound file should be part of the Copy Bundle Resources build phase. The file must be in the Copy Bundle Resources build phase to copy the file to the app bundle when Xcode builds the project. The sound file must be in the app bundle to load it and play it.

   

@SwiftDevJournal thanks a lot , @DarkhorseStudios , do let us know if you got it resolved ..

   

Hacking with Swift is sponsored by RevenueCat

SPONSORED In-app subscriptions are a pain to implement, hard to test, and full of edge cases. RevenueCat makes it straightforward and reliable so you can get back to building your app. Oh, and it's free if your app makes less than $10k/mo.

Learn more

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.