Can't open Data Model File in Xcode - ios

Using MacOS Sierra(10.12.1 (16B2555)) and Xcode 8.1(8B62). Created a new Project without selecting "Use Core Data". Now when I create a new Data Model, I can't open it in Xcode editor.
Even if I right click, Open As-> doesn't show any option.
I had a look at this question, but the answer doesn't help me.
I have deleted and re-added file, even re-generated the data model.
I have cleaned project and build folder.
Also committed to source control and then retried.
Even restarted Xcode and Mac, but nothing seems to be working.
How can I use Core Data in my project now?

You could try open the package contents of xcdatamodeld, drag out the file inside with the same name and use it instead. I had the same problem and thanks to this answer solved it.

I created the same file in a different folder to test if it will work and it did. I deleted it and tried to re create it in the folder i wanted then it worked

Related

Xcode could not open file

I am making a mini tweet and working with team members using RxSwift and MVVM. But when I try to open a new file, it doesn't open. Restarting the computer and restarting the app is the same.
I'm working on the same branch as a team member, is that a problem? Why won't it open
NetworkingAPI and ViewModelType is new created file but The file color is weird
There are lots of reasons why that specific file went missing.
You might've dragged that file from somewhere into your Xcode project and you thought that it was copied properly onto your project folder and deleted it from the original source folder.
Merge issues.
Similar to #2, another team member of your project pushed the file in a wrongful way.
There are of course also ways to recover it.
Check your local machine.
Ask for the most updated file from your teammate.
Check your commits, and simply copy the whole source from there and fix it in your Xcode project by making a new file in your project folder.
I think the #3 should suffice.
You have the reference in Xcode but the files are missing.
This happened when merging and you had .xcodeproj conflict then someone solved it in the wrong way. Check this as reference: https://stackoverflow.com/a/12907864/3933094

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.

How to open Xcode Projects on a Different Mac/Hard drive

I recently got a new hard drive and reinstalled Mac OS X on it. I copied my entire folder with all my Xcode projects over. However when I tried booting up one by clicking the project file, Xcode opens up with only the project file present. All of the files with actual code on them are not appearing.
I tried to add files but even that would leave most of the files with code on them greyed out in the finder.
Question, what is the proper way of transferring these projects specifically in Xcode 7? I have not been able to find anything concrete.
So, the only way I know of to do this efficiently is to load up the project file XML in your favorite editor and go manually fixup the paths. I don't recommend this.
Unfortunately, the way to do it through the UI is for each file, you need to open the Utilities Bar on the right, select the file, then update the path via the little folder icon in the Identity and Type section. Here's an illustration:
Then repeat for every file in your project. Sorry.
i had this same issue i mean you could always manually transfer code through word documents or notes, but for me i had copied the entire project folder and the document transferred just fine just make sure you transfer all of the files with it and not just the one file for the project itself
delete the xcode application and reinstall it from the Mac App Store.

No Assistant Results

I am having an issue where the code associated with some of my View Controllers is not showing up in the Assistant Editor window to the right of the Storyboard. It says "No Assistant Results" where the swift code should be.
Things I have tried (There are many things):
Cleaning project
Deleting DerivedData
Creating new, identical View Controllers to see if the issue was just in those particular views.(the same issue occurred)
Deleting and Reinstalling Xcode
Restarting my Computer.
NOTE: I also am getting a warning at the top of the editor: Internal Error has occurred, source Editor functionality is limited.
Ok, I've had this problem before. I couldn't remember how I solved this so I searched on Google and found this question. But this time, nothing helped me. These are the things I did. I believe the last one solved this.
Clear Derived Data. Go to Terminal and enter this: rm -rf ~/Library/Developer/Xcode/DerivedData
Quit the whole Xcode.
Close all tabs of Xcode and make sure to view some class files instead of Interface builder and go try again viewing assistant results.
Remove the assigned class to the View Controller nib you think causes the problem, then assign the class again. Boom! Solved!
This method worked for me: (Xcode 10.2)
1- Select the broken ViewController on the StoryBoard
2- In Identity Inspector, change the item in Class to another class (any class)
3- Change the Class back to related class
4- Save and close the project
5- Reopen the project
What worked for me was to close Xcode entirely, open again, and then I tried assistant.
Just do a simple close the app and open the app again. It worked for me
Deleting derived data did not work for my problem.
This is how I solved this when I encountered this issue,
Go to the file that contains your class, go to File inspector > Target Membership, and then make sure that there is a check mark in the target of your project.
I hope this solves your issue.
Go to Assistant Mode on the upper right.
Click Command + Shift + T. New window will be opened and close the old one. You will be able to see something. Now go to Top Level Objects and select your file.
Click option+alt and click on the view controller you want to present.
Argh! This annoyance happens to me all the time.
I'm not 100% sure I know what the fix is, however I think I may have just "fixed" this a few seconds ago using the following voodoo:
1) Delete derived Data
2) Close xcode, reopen Xcode. Maybe Wait for indexing to finish?
3) View a source code file (.m,.h, .swift) in the main editor, the assistant editor should now show "Counterparts".
4) Change this to "Manual" rather than "Automatic"
5) Switch back to your nib/storyboard
6) Change back to "Automatic" rather than "Manual"
7) Probably continue pulling hair out :)
Edit
Seems as though maybe only step 3 is required as this happened again just now.
I had this issue and was able to resolve it. I resolved it by viewing the storyboard as source. I then removed everything in and including the tags (Saving it to restore later). I then went back and viewed the storyboard normally and created a new ViewController. Once the new ViewController was on the storyboard the assistant editor acted as normal. I then went back and viewed the storyboard as source code once again and replaced the current tags with the one I removed previously. This resolved my issues hopefully it will help for you.
For me (Xcode 11) it was cause by installing cocoapods, tried all the trick that I could find. Finally this helped me. Go to Xcode File Menu -> WorkSpace Settings -> enable legacy build systems
The same problem happened to me.
I only have to restart Xcode (12.2)
For any one who is encountering the same problem in Xcode version 13.3
Explanation: for me, the reason why it wasn't working is that I created a controller, view, and model Folder and I put the Main.storyboard inside the view folder and the viewController.swift inside the controller view, therefore when I try to access the assistant Result Xcode doesn't know where the viewController file is, so he is not able to connect between the storyboard file and the latter.
Solution: What worked for me is that I simply ran the app and it automatically connected the viewController with the storyboard.
I hope this was helpful.
I don't know if this is still helpful or not, for what is worth, the way I managed to restore this when it's been working perfectly and all of a sudden it stopped is by changing Assistant Editor view-mode.
I usually have it in Assistant Editors at bottom, so just change it to whatever else, such as All Editors Stacked Vertically and go back, and it should be working ok now.
xcode 8.3.2, if it's any use.
I tried various ideas mentioned here but nothing worked for me. So in the Project navigator, I right clicked on the .DS_Store file, clicked on Delete, and then chose "Move to Trash" on the confirmation prompt. After closing Xcode and opening it again, a new .DS_Store file was created. The Assistant Editor is working again and the .h and .m files appear in the Project navigator again. I am using Visual Studio for Mac which communicates with Xcode. Today I had to close and open both Visual Studio and Xcode after deleting the .DS_Store file.
you may have changed the name of the .swift file after you connected your IB oulets and IB actions.
select main.storyboard and select your view controller.
at the far right select identity inspector.
check if the class name is the same name as your .swift file, if it is not you need to put in the file name and the assistant should show up now.
In my case, the class name of File's Owner is incorrect (the class doesn't exist). I corrected the class name and it works again
Go to the view controller Identity Inspector (see the image). Change your controller to something incorrect, then change it back.
I had the same problem and I realized that selecting the Outlets option in the top of the Assistant Editor View solves the problem.
In addition to this, I found that if your classes are in several groups for some reason Xcode losses the reference to the class.
I setup the folder for the derived data when I installed Xcode in a folder I deleted cleaning my disk! So I created a new folder and I assigned in locations as above. Thats it! I was cleaning a file that didn't exist.
If the problem started after renaming the ViewController, first check whether you've changed the class name inside the ViewController file as well.
I have disabled xcode indexing, so after enabling indexing it starts working
Faced same issue.
For me it happen when I moved my view controllers to the new group.
The solution was unfortunate, but at least it worked again - I just moved the files back to the origin folder.
In Xcode 12.x, this will happen if you rename your ViewController file after creating it. If this is the case, just simply delete that ViewController file, and create a new one with a file name that you will not change, and then the Assistant window should automatically populate.
Please make sure that there is
no error in your project and your project is complining succesfully.
In my case, there was an error om some other class due to which I was not able to see assistant results.
After 7 imaginary hours, I finally found the answer. this is only for the storyboard for other people out there reading this is the answer if it does not help I don't care but here it is.
(This is an example project I cloned from GitHub)
Just select veiwcontroller.swift in the document outline, it should work.
Here is a screenshot.
Like i told, example project.
Had the same problem on Xcode Version 13.0 (13A233). As Glenn Posadas mentioned, deleting the derived data rm -rf ~/Library/Developer/Xcode/DerivedData then closing and re-opening the project solved the problem for me.
I had the same problem, so I re-organized files in folders and it got fixed. If you have the file in a specific folder, please put it outside that folder.
Try this (XCode 13.2.1):
In Storyboard, select the object whose class definition you want to
bring up in the assistant editor.
Delete the custom class in the Identity Inspector, being sure to
press the return key to lock in the change.
Quit XCode and reopen.
Re-enter your custom class name in the Identity Inspector.
I tried all the suggestions above and this was the only thing that worked for me.
Xcode 13.3.1
None of these worked but I did a clean and shut everything down and reopened and it worked.
One reason for this happening is moving the swift file to a different folder. If I move the swift file out of the folder, the assistant view works again. If I move the swift file back into a folder, it fails again.
After trying several tricks mentioned here, this seems to have finally worked for me:
Close the project,
Rename the project folder in Finder (i.e. the folder containing the .xcodeproj file)
Double click the .xcodeproj file to open the project.
It seems that paths stored in local cache files can be stubborn about being updated.

Deleted class drops error message unknown>:0: error: no such file or directory:

So me and some friends working on a bitbucket project and already realized that bitbucket sometimes doesn't sync all the files. But here is what happened:
I continued working and created an class, I basically copied an old View Controller (called WelcomescreenViewController.swift -> CreateAccountViewController.swift) and made some adjustments in the main storyboard. Here I deleted all the old outlets in the new one and then made an own class for it as ViewController and connected it with it in the main storyboard.
What now happened is that there were some problems and I reverted everything and deleted both things again. And basically now Xcode still kind of thinks that there should be the class. It always drops the message:
I also made a screenshot from the directory with my files as it is now:
I tried to create the class again, so that Xcode is happy but it doesn't help. Is the file somewhere linked or what shall I do, to teach Xcode hey everything is fine, don't mind about the old file CreateAccountViewController.swift?
Make sure in your target settings, under Build Phases > Compile Sources that your file isn't listed there:
Also, just check it somehow hasn't been added to Copy Bundle Resources.
If you're developing a pod, and the deleted file is in the pod, try pod install to rebuild the framework.
Check if the deleted files are still in Project, if yes, delete. build ...

Resources