Xcode IB Can't Read Archive? - xcode

I just created a new project from a template and when I try to build the project I get a "Could not read archive" error for each nib file from the compiler. I did some Googling but could not find an explanation or steps to debug. Has anyone run into this error before or can someone explain what it means?
When I try to open the nibs with Interface Builder I get the same error in a pop up.

I'm an idiot. Project name included an ampersand '&' character. Reread the Nimble Kit Coding Examples. and saw the little warning against using special characters "especially '&'" near be bottom of the Xcode compiling error segment in order to figure this one out.

I tried a bunch of things that never worked. I finally solved this issue by simply deleting the item out of XCode (just remove the reference..DO NOT..I REPEAT..DO NOT move it to the trash!!). Then, Add the file back into the project by Selecting "File" - "Add Files" or right clicking some folder in the Folder Navigator view and selecting "Add Files". I then cleaned the project just to be on the safe side and after that I built the project and it worked!

Related

How to move files in Xcode without causing "Cannot find 'FileName' in Scope"?

I want to make my project more organized, so I created new groups and dragged files into those groups. I am doing all of this in Xcode, not finder or terminal. However, now, Xcode shows "Cannot find 'FileName' in Scope" errors next to references to classes in those files.
How do I solve this problem?
I tried building the project and cleaning the build folder.
I ran into the same issue today with Xcode 12.2 and an iOS 14.2 project. I created a file for a new struct, wrote some code in ViewController that created instances of the struct, and then for housecleaning I moved the struct's .swift file. At that point I saw the error "Cannot find [type] in scope."
Product | Clean Build Folder didn't do the trick.
Closing and reopening Xcode worked for me.
I'm not sure if the initial clean helped or not.
There are more detailed answers here, and your particular case may be covered:
SwiftUI 2.0 CoreData issues with new project - 'Cannot find type 'Item' in scope'
I fixed a similar issue today using Xcode 12.3 (12C33):
Solution
Removed the impacted files from Xcode (without trashing them)
Tried adding the files back with the create folder references option selected
Found that this action generated Cannot find 'type' in scope error
Resolved the error by removing the files references and select the create groups option when copying the files back into the project.
BTW - I found these methods work while using either the Add Files option or dragging the files/folders into the project.
I found some "hack" to fix it.
Lets say you wanna move folder Models to your project. Open AppCode and create Model group using IDE tools. Then open XCode, select Model folder and perform Add files to "Model" action. It worked out in my case.
From my understanding, the problem is with forlders, not with files.

Problems after upgrading to Xcode 10: Build input file cannot be found

I upgraded my Xcode SDK to version 10 last night and then find I cannot build.
I'm getting this error:
Build input file cannot be found:
'/Users/call01/Library/Developer/Xcode/DerivedData/Comp-Lite-Apps-gytvmossqptokeafrddvvmnlzadk/Build/Products/Debug-iphoneos/SG11.app/SG11
which did not exist before my upgrade and I'm tempted to revert back but would like to stick with version 10 if I can resolve this issue.
Try to switch back to the Legacy Build System (File > Project Settings > Workspace Settings > Legacy Build System)
For Swift files or files that belong to the project such as:
Build input file cannot be found: PATH/TO/FILE/FILE.swift
This issue can happen when files or folders have been removed or moved in the project.
To fix it:
Go in the project-navigator, select your project
Select Build Phasestab
In Compile Sources section, check for the file(s) that Xcode is complaining of
Notice that the file(s) have the wrong path, and delete them by clicking on the minus icon
Re-add the file(s) by clicking the plus icon and search in the project.
Product > Clean Build Folder
Build
You generally find these missing files in the Recovered References folder of Xcode in the project tree (look for the search bar at the bottom-left of Xcode and search for your complaining file):
Deleting them from this folder can also solve the error.
For me In Xcode 10, this solution worked like a charm. Just go to the Recovered References folder and remove all files in red color and add it again with proper reference.
If Recovered References folder was not found: Check for all missing files in the project (files in red colour) and try to add files references again.
Just check the path to .plist file in Build Settings of your target
Funnily, closing Xcode and reopening it might also be enough.
This worked for me in Xcode 10:
Click Project icon/name in your Xcode project
Go to General tab
Click [Choose info.plist File] under Identity section
Select the info.Plist file
Check Info tab to see if info.plist was loaded successfully
Build and run
This is an architecture problem. Do not change to legacy build system!
I got the same error, but what solved it for me was this:
The top says architectures in VALID_ARCHS are also excluded in EXCLUDED ARCHS. I was messing around with them to get a Swift Package to compile in Xcode 12, and have spent hours on this.
It would compile on the simulator and not on a device.
The Solution:
Go to Build Settings
Ensure "Architectures" contains 1 entry : $(ARCHS_STANDARD)
Ensure there is nothing in "Excluded Architectures"
Now scroll right to the bottom of Build Settings.
Make sure the VALID_ARCHS is exactly the same as this screenshot.
The arm stuff is $(ARCHS_STANDARD) again.
If VALID_ARCHS doesn't exist, add it with the + button.
Clean (cmd-shift-K)
Your project should now build perfect on both the simulator and device!
If it doesn't work, you need to make sure all these settings are the same both in your target build settings and the project build settings.
Note, if you have a Mac with Apple silicon, you may not need to do any of this.
The above solution eventually works for me; however, I need to do some more extra steps to finally make it to compile successfully. (These extra steps were required even on Xcode 9.)
Xcode: File -> Workspace Settings -> Build System: Legacy Build System
Xcode: Product -> Clean
Rotate to compile thru different emulator types, such as "iPhone 8", "iPhone 8 Plus", etc. (They might fail or might not.)
Eventually compile on "Generic iOS Device"
I fixed this issue this way: go to your project's Build Phases (click on project icon at the top, and then click on Build Phases). Search for your file there. If it's there (it'll be grayed out), delete it. Then clean (shift + alt + command + k), and run! Hope it helps.
If the error says it can't find Info.plist and it's looking in the wrong path, do the following:
Select your project from the navigator, then select your target
Select "Build Settings" and search "plist"
There should be an option called Info.plist File. Change the location to the correct one.
None of the above worked for me, but this did:
Open project in Finder, right click on your .xcodeproj file and show package contents
Open project.pbxproj in a text editor
Find the reference to your missing file
Edit path = "path/to/file.swift" to the actual location on disk and save the file.
Rebuild the project
In my case I had a build script that generated the .app binary (Buck).
The Buck build script ran in parallel with Swift Embed build step. Because the .app binary was not generated yet the Swift step would fail.
In my build script I added "$BUILD_PRODUCTS_DIR/$EXECUTABLE_PATH" under "Output Files".
This tells Xcode's New Build System that this script will output the app Binary and in turn Xcode will make sure to synchronize any build steps that depend on this artifact.
I ran into this error after renaming a file. Somehow Xcode didn't correctly rename the actual file on disk.
So it wasn't able to find the file. Sometimes the files gets highlights with a red text color. At other times the Swift icon in front of the file was getting a gray overlay.
The fix was simple.
Look into the error and see exactly which file it's unable to find.
Select the file that can't be found.
Go to the 'File Inspector'. It's on Xcode's right navigation pane.
Click on the folder icon.
Select the correct file.
Clean build and run it again.
Open the right navigation pane where your project files exist
OR JUST click on cmd + 1. Then search for "Recovered References" folder. Open it and delete all red files, then everything will work so fine.
I had this happen for building my unit tests. This may have happened because I deleted the example tests.
I removed the Unit test bundle then re-added it as shown in the pictures below and all was well again.
I had a similar issue after upgrading to a new swift version recently.
Moving files around caused my xcode project to reference items that were no longer in the project directory giving me the Error Code Build Input File Not Found.
In my situation I somehow had multiple files/images that were being referenced as described below:
In the image above.
Navigate to your Targets page.
Then Click on the Build Phases tab on the top.
Scroll Down to Copy Bundle Resources
Find the affected files and remove them. (hit delete on them or select them and hit the minus button )
It was in here that I somehow had multiple files and images that were being referenced from other folders and the build would fail as they could no longer find them. And I could not find them either! or how Xcode was still referencing them
I hope this helps someone else !
This worked for me
try deleting the red colored files
delete the files in derived data
clean the build folder
then try building by using "new build system" from file->workspace settings
I had the same issue. The problem was that I didn't have any file under the Target > Build Phases > Compile Sources. The problem was solved after I added at leas one file to Compile Sources.
Not that I did anything wrong, but I ran into this issue for a completely different reason and kinda know what caused this.
I previously used finder and dragged a file into my project's directory/folder. I didn't drag into Xcode. To make Xcode include that file into the project, I had to drag it into Xcode myself later again.
But when I switched to a new branch which didn't have that file (nor it needed to), Xcode was giving me this error:
Build input file cannot be found:
'/Users/honey/Documents/xp/xpios/powerup/Models
Extensions/CGSize+Extension.swift'
I did clean build folder and delete my derived data, but it didn't work until I restarted my Xcode.
In my case, the file (and the directory) that XCode was mentioning was incorrect, and the issue started occurring after a Git merge with a relatively huge branch. To fix the same, I did the following steps:
Searched for the file in the directory system of XCode.
Found the errored file highlighted in red (i.e, it was missing).
Right clicked on the file and removed the file.
I tried building my code again, and voila, it was successful.
I hope these steps help someone out.
What Xcode was complaining about was a XIB file I got it working by going to Project -> Build Phases -> Copy Bundle Resources, removing the "problematic" XIB, cleaning (CMD+Shift+K), building and adding it back again.
There is also one possibility that sometimes when you move your files to different folder and especially when you move your info.plist to other folder, you need to define the location of that file. To solve this problem, simply click on your project blue icon on the top, and you will see a button in place of project name and bundle id, click on it and locate the info.plist file there, clean and compile happily.
I ran into this problem soon after upgrading to Xcode 10, but that was not the issue.
I tried changing the build system, but that gave me a separate error that meant the same thing. Generally saying "File X can not be found".
There are multiple things to check when a file can not be found.
Recovered references Folder
Apple does this nice thing where if it detects a reference to a file that doesn't exists it will add this reference into a group called "Recovered References"
That is nice of Apple but it doesn't always work.
Build Phases Compile Sources
In this list, there could be meta data for a file that the project is suppose to compile, but the file does not actually exists and it's attempting to find the file at the given path. In this list it will be dimmed out, delete them and re-add them by toggling the file's target dependencies or manually removing it and dragging it in.
File's Path
Double check the file path that the error is printing out and the file path for the file in finder. You can easily see this by clicking on the file in Xcode and checking the "Show the file inspector" tab (the left most tab). If these paths are correct then you are good!
Dimmed out files in your project that are not in recovered references or red
This one pissed me off because it's not obvious about what happened, but basically if you go into finder and move a file to a different location with out updating the reference in the project it will throw the error as the file no longer exists there. The only indication I have found for that is that the file in the "Project Navigator" tab (left most tab) is very slightly dimmed, but when you go to delete this file Xcode doesn't prompt you to delete the reference or send to trash. You can fix this by deleting the file and re-adding it to the project or going to the "File Inspector" tab and click the folder icon next to the path and change it to the proper location.
Either way, the error indicates that it can't find a file, switching to the old build system is a bandaid for a more concrete issue. We as developers understand that a compiler just wants an artifact to be listed at the end of a file path. Somewhere the path is not correct! We have to find where that is!
My issue was resolved with item 4 listed above. Hope this helps somebody.
In my case I accidentally deleted one third-party xcodeproj folder I used in my app.
If you tried profiling, and then it didn't work, and now you cannot build, go into your Target pane (via the Project Icon), Switch to the Build Settings tab, search for PROFILE - and set CLANG_USE_OPTIMIZATION_PROFILE to "No".
In my case, I had created a new test target and deleted the default swift file so it was left with just the info.plist. Adding a new file fixed this.
The "Legacy Build System" solution didn't work for me. What worked it was:
Clean project and remove "DerivedData".
Remove input files not found from project (only references, don't delete files).
Build (=> will generate errors related to missing files).
Add files again to project.
Build (=> should SUCCEED).
I know that this is an old subject, but I found the issue with xcode 12.3 and was related to an error while doing the CopyPlist of the main.Storyboard during compilation.
Actually, changing the build settings to "Legacy Build Setting" worked, but it is deprecated, so I discarded it because is a short term solution.
Check this:
With that setting, worked for me. Before I had "Copy plist".
After struggling with this issue for about 45mins, here is a super easy solution that worked for me.
On the project explorer, click on the file/folder that is in red colour (means project is not able to locate the file)
Look at the details tab in the file inspector (generally to the right of the screen - see the attached screenshot)
Click on the folder icon and locate the real file/folder in your local machine.
That is it. This should do the trick. Basically help your xcode locate the directories and update the reference cache.
Random, for Cocoapods: I hadn't added my test target to my Podfile.

Multiple errors ocurred while copying files - but, can I see what they are?

There were around 200 files I had to delete in my Xcode project (and yeah, they were deleted properly), and now I have to copy 200+ files are supposedly replace the ones I just deleted.
I keep getting "Multiple errors occurred while copying files". The Xcode window doesn't show the newly-added files, but if I explore the project folder using the Finder, I can see that the files were indeed added - well, there most likely was a certain file that could not be copied and thus caused the error. Problem is, I have no idea which one nor why.
Now then, is it possible to get Xcode to tell me what the problem is rather than telling me there is one?
Edit: Okay, I did discover that some of the new files shared the same name as some files that were not listed in Xcode, which explains the error. However, I am still interested in knowing whether there is a way to know that the "Multiple errors" actually are whenever Xcode says t his.
When Xcode finds a duplicate file, it generates this error, and then it fails to add references for the files that it did manage to copy.
Rather than deleting files from the finder and starting over, you can do this:
Open the Finder for your project, where your source files are located
Command-click the ones for which your references are missing (and if you click others, it won't really matter)
Drag them into Xcode. When the confirmation dialog comes up, unset the "Copy items into destination group's folder (if needed)" checkbox. This will tell Xcode to make references only.
I deleted the files from finder and then added again the files via Xcode, that worked for me.
This error sometimes occurs when the code is not merged properly. The missing files will not be available in Xcode but once you open the finder containing this project, you will be able to spot the missing file.
The simplest way to add these missing files back to the project is:
1) In your Xcode, navigate to Build Phases Tab.
2) Under Compile Sources, tap on '+' to add back the missing file.
Sometimes the missing files will be greyed out in the build phases, just tap on '-' and add them back.
For me this is worked. I tried to add files which are already in my bundle. So make sure you are not adding files which are already added. I hope it helps someone.

Xcode 4.6.2 error: "cannot run on the selected destination"

I've been having this problem for a couple weeks now. All of a sudden this happened to my project and I havent been able to fix it. Its a basic tab-bar app and i've barely even started heavy coding on it. Running xcode 4.6.2 (tried on 4.6 and 4.6.1 also).
The actual error says:
"Cannot run on the selected destination
The selected destination does not support the architecture for which the selected software is built. Switch to a destination that supports that architecture in order to run the selected software."
Thanks in advance.
Well here's my new fix: I had (for some reason) changed the highlighted line below:
I had changed the ${EXECUTABLE_NAME} to something else. Changing it back did not fix the issue immediately: I had to first click the + to add a new row then delete the new row.
My app runs fine now
OLD FIX:
OK, so yes, it's true, there are other questions like this one. They helped me figure out a different (and stranger) solution.
I right-clicked on my .xcodeproj file and chose "Show Package Contents"
I then opened "project.pbxproj"
I copied all the text from it to another file, deleted all the text from it and saved
This "crashed" my XCode Project that I had accidentally left open in XCode.
I closed my project, then pasted the original contents of "project.pbxproj" back into "project.pbxproj"
I saved "project.pbxproj" and closed it
After opening my XCode Project again, I was able to run it on my device!
To me, it doesn't make sense why this worked because I didn't modify an files... But it did, so hurrah!
PS
Back up your project beforehand, just in case.
EDIT: Well mine has stopped working again and I can't use the above method to fix it...

Xcode 4 shows no files after loading project

I've loaded a project in Xcode 4 after not looking at it for a while. Xcode shows its progress bar and indicates in text that the project is loading, and it appears to finish, but then there are no files shown in the hierarchy or flat views. There is nothing showing in any view (except for one breakpoint in the breakpoints view).
Any ideas? Xcode gives me zero indication that anything is wrong, it shows me nothing.
I just had the same issue. After a few hours scratching my head and trying all kind of things, I finally found a fix: remove the whole package 'project.xcworkspace' inside the XXXXX.xcodeproj package.
More specifically, when you find the 'XXXXX.xcodeproj' file, right-click it, and select 'Show Package Contents'. This will get you inside the package where you will find the 'package.xcworkspace' file. It is best to do this while the Xcode project is closed.
Maybe that will work for you or for others with the same issue in the future...
Some of the project views have the "Recently Changed" filter icon. For me the problem was: i had that enabled in the Project Navigator, so it was only showing the files i recently changed. It looks like this.
I'm using Xcode 6.1 though.
I had a similar issue. After archiving a project the files would disappear from the project navigator.
It turned out that somehow XCode had added the word "main" to the searchbar below the project navigator so that almost all files where invisible. Quite frustrating.
It might be the same case for you..
For those who make it here, I was opening a older version of a similar iOS project after upgrading to the latest XCode (6.2), and was seeing the symptoms labeled in this question (missing files, folders etc.)
My solution: at the bottom left of the screen, unselecting 'Show only files with source-control status" which happened to be set on (it's blue when on). The icon looks like a 4-pt star inside a square.
remove the whole package 'project.xcworkspace' inside the XXXXX.xcodeproj package. may cause to any other error so please ignore and trying finally
You can quit xcode and reload again your project it help you
This happened to me when I tried to do an alt-tab, on a VM running in TeamViewer in Windows - Click the search bar below, enter delete multiple times and the invisible search term cleared up
I had the same issue. Besides the answers above, it could also be that you have already accidentally opened the project in another Xcode window... Close that and reopen everything and it should work.

Resources