I was reading the document of XCTest(and personally i think the documentation for this part is not that enough) and I thought I should give it a try for a new project(a MAC command-line project, not and iOS project). and then I faced complaints about linking issues--the test case building failed because the conresponsding class .o(if I am not wrong) files are not found. (the error mes here was not recorded by me, sorry)
Then I wanted to delete the test project and in the end I did not even manage to remove the test project. So seriously, how to remove an exsiting project from the solution if the notion in VS applies here?
After failing at that, I removed the auto-generated test file and created my own test case file and strangely, although Xcode detects the existence of the new test case and test method, the build failed and it failed with no issues--no linking issue, no syntax or whatever issue but it just failed. Now I do not know how to move on now as I do not even get a complaint or an error.
I don't know enough about the state of your project to be certain what the problem is, but here is something to consider: If Xcode added a new build target for your tests, be sure that the .m files that contain the classes you are testing are included in the new build target. You can do this by clicking on the relevant .m file in the Project Navigator and looking at the "Target Membership" in the File Inspector pane. Make sure the box is checked next to the test target.
Related
I just upgraded to Xcode 10, and I suddenly face this error when I try to build, any ideas how to fix it? I tried cleaning derived data, but without any luck.
If you use CocoaPods, click Xcode menu file -> Workspace Settings , And click Build system choice Legacy Build System
If you not use CocoaPods, same of top , select Project Settings
If your app is generating the error related to the multiple .app files just like mentioned above in question then removing the .plist files from "Copy bundle Resources" WILL NOT WORK.
If the error is related to .app file then follow the following steps.
Select the Target.
Go to Build Phases tab.
Remove the items listed in Output Files
Compile the code if it compiles successfully then not follow the next steps.
If code does not compile successfully and Xcode may give you an error related to "Library not found". Then add the missing library in General Tab in Linked Frameworks and Libraries that Xcode mentioned in the error.
Keep adding these libraries (that Xcode ask through compile errors) in Linked Frameworks and Libraries until the code compiles successfully.
Hope this helps.
You can try to change the build system to Legacy,
File > Workspace Settings > Build System > Legacy Build System.
I also faced this issue in xcode 10 but it was because of adding the same framework in main project + other extensions (watchkit or siri extension etc).
I added ObjectMapper in podfile for my main project + for my extensions. When I compiled it gave me an error that multiple command produce and also shows me which framework is causing this issue. Now its working fine for me as I've removed it from my extensions I wasn't using it in my extensions.
Don't know about your issue may be you can check your podfile.
If this is CoreData related. The issue is that you are trying to generate the NSManagedObject subclass but you need to set the 'CodeGen' option to Manual/None. This option is defaulted to Class definition and this would regenerate the code thus creating this issue.
i encountered this issue as well while working with CoreData.
in my .xcdatamodeld file, it came down to the fact that, during the creation of my various Entities, i had copy and pasted one multiple times (thinking i was saving time because various properties were similar enough that i thought this was a good idea).
the resulting Build error Xcode 10 - 'Multiple commands produce' occurred because i forgot to check and make sure the new Entities were set to their own unique corresponding class to match the new Entity in the Data Model Inspector pane.
unfortunately, it took me two days to figure out the original Entity's Class Name was still in place.
so lesson: careful when you copy/paste/duplicate Entities in CoreData.
(... i guess :0} )
some time saver. oops! hope this helps someone.
I had this same issue with Core Data entity class. I had forgotten to select Codegen Manual / None because I do not allow mine to be autogenerated. So I had a class in place and also it was trying to generate one.
I am currently developing a swift framework for my iOS class.
Here is the project structure :
I would like to test my class named SimpleCoreData, but when I go to the generated ESGISimpleCoreDataTests file, the import (also generated) isn't accepted:
Cannot load underlying module for 'ESGISimpleCoreData'
So I checked this other topic, and verified the targets, but everything seems fine.
framework:
tests build phases:
I am beginning in Swift, so I may have missed something obvious. Can you please help me with this one?
Finally, after examining each commit to see where it breaked, it turns out that the problem was probably coming from a unit test file I created, which had the same issue (probably didn't created it correctly), and then only removed its references instead of moving it to trash.
So I went a commit backward, used the default unit test file generated, and it worked.
Here's another variation on this theme. πΆπ΅
I imported a folder of files into my main project, and in that folder was a file which had import XCTest in it.
The compiler didn't flag this problem, and I didn't see it until I used finder (like CodingMouse).
Once I moved this testing file to the UITests folder and changed its "Target Membership" to the UITests Module, I did a clean and build to get everything working again.
So the takeaway from this is the compiler won't always point you directly to the actual problem. Using finder, scan through your files and confirm nothing looks suspicious or out of place. π
I have a growing swift project that I have been writing both unit and UI tests for along the way. My UI tests run just fine, but my unit tests have stopped compiling. I am using "#testable import X", but anytime I try to access a class from the project, even if I make that class public, I get a "Use of unresolved identifier" error. I have no idea what I could have changed to cause things to start failing.
Choose "Clean" from the Xcode "Product" menu and then recompile. That will often get it working again. For some reason, we have to "Clean" before the classes are made available to the test target.
My original answer below outlines the old solution before #testable was available to us.
--
Make sure the source file for PostCell is included in the list of source files for the tests target.
You can do this by going to the tests target and adding it to the list of "Compile Sources":
Or by clicking on "Target Membership" to the "File Inspector" for the source in question:
So after I create an Xcode 6 project, even if I haven't written any code in it, if I try renaming it by double clicking the bolded program title in the upper left hand corner of the navigator and then confirming that I want the checked items' names changed, I get the following error when I try running it: "clang: error: linker command failed with exit code 1 (use -v to see invocation)"
I've even tried using the find tool to see all the things named the previous name, including the info.plist (which I think is the problem) and changing them to the new name. By renaming the info.plist manually I get an error saying that doesn't exist.
What am I doing wrong?
I saw the same error after changing the name, and I was able to fix it by clearing the "Test Host" values in the Build Settings of my "Tests" target:
Alternatively, If you need your tests to be able to run after changing the name of your project, you should be able to update the MyProject.app/MyProject value in both fields to reflect the new name of your project (ie. MyNewProject.app/MyNewProject)
If above method(s) doesn't work and if for now you don't feel like needing to test anything in your project, just remove your project test target.
Later on if you need to create some tests, you will still be able to add test targets again.
Go to the Build Settings of my "Tests" target then change the paths from the old project name to your new project name
Test Host
- Debug Build/Debug-iphoneos/OldProjectName.app/OldProjectName
- Release Build/Release-iphoneos/OldProjectName.app/OldProjectName
Test Host
- Debug Build/Debug-iphoneos/NewProjectName.app/NewProjectName
- Release Build/Release-iphoneos/NewProjectName.app/NewProjectName
Just simply clearing them would break your tests so you need to replace them with the new project name.
Ran into this too, after copying and renaming the folder with an xcode project. I think it's a bug in xcode. Best file a bug with bugreporter (https://bugreport.apple.com/). Removing the test target from my project fixed it for me, too.
Here is what I've done to fix the similar problem since I changed the project name and folders under the project.
Select project file : projectName.xcodeproj
Right click on the project file and click "Show package contents" to open project.pbxproj file.
Once ope project.pbxproj file, replace all from old project name (whatever you changed from) to new name.
You can change the name of sub folder if you changed folder name too.
Hope this help.
There are different places where you should check for the rename.
You should check for the "old" project name in the test target and in the project target. Search for the old name string and rename them manually to the new name.
If you doesn't use the test target you can delete this target.
There are many places you have to check upon re-naming. This approach does not seem at all practical.
If you really need to do this, I recommend creating a new project and just copying the necessary files over to the new project.
While I was busy trying out stuff for this question, I accidently removed the xcdatamodel-package.
I found out that recently there was this question which mentioned the following:
For some reason, the xdatamodel was removed from the build settings. I added it back in and it worked.
I tried doing what he did, but I don't know where to start.
I recreated the package, but when I try to set an attribute value, I get +entityForName: could not locate an entity named 'EN'...
All I know is; it did work until I started fooling around with not-tutorial-attributes and stuff.
What they're getting at in that other question is that when you add a file to a project, it's not necessarily added to the current target. You can have multiple targets in a project, and you can add files that don't get compiled (e.g. developer documentation), so it's possible to add a file but then have it just sit there and not get built.
If you select the file in Xcode and open up the Utilities pane on the right, there's a section that shows target membership. It looks like this:
This one shows that the file belongs to the project momdecTests but not to the project momdec. Make sure your app target is checked here.