Multiple Targets in Xcode: "File not found" - ios

I am having a single project file. Then I created another target for a "Lite" version. I changed the bundle ID and product name for each target and am able to continue working this way.
But when I added a new custom class to the project, I try to use the class in existing VC by #import "NewClass.h" but it only works on one target, on the Lite target, it says:
File not found
Why is this and how to solve it?

While adding any new file and if you are working on multiple targets and you want that file in both the targets then you need to check both the targets while adding file
Check screenshot

You need to add the file to both the Target, so it can be accessed.
Click on the file you have added and then go to the Utilities Area in the right and click on File Inspector. You will have section called 'Target Membership', please select the target from the list of Targets.
Alternatively approach :
Select the Target in which you are getting error then got to Build Phases -> Compile Sources and make sure the file is present there.

If you forgot to add a target when you creating a file, you can add later by selecting the file in project navigator and then check/uncheck the target(s) in the File Inspector (on the right)

Related

Using the same code for different target in Xcode

I want to use the same code for different target in Xcode. I am able to create the target using the Duplicate method and then I am able to change scheme name as well.
Now the real scenario comes, I want to be use my code in centralised way like for new target, I don't want to copy and paste the Main.storyboard and xib as well, so, ideally what would happen, if I would change anything in one place, all target would share that.But the issue comes, that ``ViewControllerinMain.Storyboard` holds the master project "module" so, when I run the child target, it could not run.
You can open Utilities panel, select File inspector tab and mark necessary targets for every file you want to share.
See attached image as a reference.
Of-course you can do it. you can use single code/file for multiple target and/or single target, according to your requirement.
Apple document for the same
Have a look at these snapshots:
For existing file in your project follow these steps to assign multiple targets
Select your file ▶ Utilities window ▶ File Inspector ▶ Target
Membership ▶ Select target according to your requirement for source
file usage
Create new file with multiple targets
Menu >> New File >> Select File Type >> Assign File Name >> Next >>
Select targets for your file.
Have you tried removing the Module and select Inherit From Target instead?

Could not determine generated file paths for CoreData code generation

While building my project for different target I am getting this error:
Could not determine generated file paths for Core Data code
generation:
Error Domain=NSCocoaErrorDomain Code=260 "No current version for model
at path
/Users/abc/Documents/Code/xyz-ios/ABC/iPhoneXMPP/SRT/Model.xcdatamodeld:"
UserInfo={NSFilePath=/Users/abc/Documents/Code/xyz-ios/ABC/iPhoneXMPP/SRT/Model.xcdatamodeld,
NSLocalizedDescription=No current version for model at path
/Users/abc/Documents/Code/xyz-ios/ABC/iPhoneXMPP/SRT/Model.xcdatamodeld:}
Path mentioned in error is "
/Users/abc/Documents/Code/xyz-ios/ABC/iPhoneXMPP/SRT/Model.xcdatamodeld
" but "SRT" folder is inside "Temp" folder in my folder structure.
How can I resolve this issue?
Similar to shallowThought's answer, I found I had to first uncheck the target, and then re-check it, and then re-build.
In Xcode, select your Model.xcdatamodeld model and tick the checkbox "Target Membership" for your new target in the Inspector.
In My Case it was a result of Model.xcdatamodeld having conflicts when Merged with Remote (Source or Head). Somehow this conflict wasn't detected by GIT and slid through as Conflict Free.
Resolution: Open Model.xcdatamodeld as xml (with textEditor) and search for conflicts (>>>). Fix conflict and Save.
In my case, I had renamed the directory in which my .xcdatamodel resided, which resulted in the old filename entry not being removed from my Target's Compile Sources phase.
All I had to do was remove the old file from the Compile Sources phase, by searching for xcdatamodeld and removing the relevant (now irrelevant...) entry in my target's Build Phases tab:
Don't forget to do this for ALL the targets that contain your Core Data data model.
Once you're done, make sure that your actual current .xcdatamodeld file is added to your target. You do this:
a) By clicking on the file in Xcode's Project Navigator (left column -> first icon):
b) And then ticking the boxes of all targets that you want this file to be a part of, in Xcode's File Inspector (right column -> first icon), under Target Membership:
In my case in File Selector Code Generation was Selected as Swift.
As I selected Code generation language as Objective-C.
Error Disappeared.
After selecting Objective-C
Product > Clean
and then Rebuild the project.
This worked for me.
Just Clean and Build worked for me after adding Core Data manually (not from the start of the project).
The answers given above are just right, but if these do not work, then:
Make a copy of your model and store it somewhere
Delete the model from Xcode
Add the model again to whatever folder you want to add it to
This solved my issue. Hope this helps.
If you are using NSPersistentContainer, it is available from iOS 10+.
You need to change the Target > General > Deployment Info > Deployment Target to 10.0+.
Then, Product > Clean & Build. It worked.
Module Inspector > Module > Current Product Module
Clean and Build afterwards.
In my case I tried to build form an external drive.
Copy the project to the internal drive, and it will work.
In my case, I was saving a new version of .xdatamodelid in the pod project .xcworkspace instead of the original xcproject. Saving it in the original fix my problems.

XCode 6: The custom class and the several project targets

I would like to have both DEV & PROD versions of my app working on my iPhone at the same time.
So I created a new target AppNameDev with a different bundle identifier.
When I launch the app on my iPhone, I get the error :
Unknown class _TtC4Wesh10InviteCell in Interface Builder file.
My custom class InviteCell is not found by the new target's interface builder. How to tell it where to find the class ?
When you click the InviteCell source file check from the File Inspector on right that both targets are checked. Or that the file exists in Build Phases - Compile Sources for both targets.
You need to click "InviteCell" class file from left side on Project Navigator and then go to "File Inspector" and click both targets (DEV & PROD) from Target Membership on the right side. I hope that helps you. For example:
Pro Tip: If you are planning to create a new file, make sure to select both DEV & PROD version targets before you click to "create" button. It will save you a lot of time because you don't have to go back and forth.

Dependencies in Xcode Workspaces

I'm trying to set up a workspace so that different projects can access the same files.
In Project A, I did a "Save As Workspace..."
Then I created Project B in the new workspace.
I can now see both in the Project Navigator.
So say I have a category that was in Project A called "UIView+Awesome" that I want to use in Project B, how do I set up that dependency?
In a view controller of Project B I get this:
#import "UIView+Awesome.h" //UIView+Awesome.h file not found
Here is how to solve it.
Click on the target that's importing UIView+Awesome.h.
Click on Build Settings.
Enter Header Search Paths into the search box.
Double click on the value cell.
Click the + sign.
Set the path to the project you're referring. Let's say it's called Awesomelib. The path is relative to the root of the referring project (the project that's using Awesomelib). For example: ../Awesomelib/src/headers/ or wherever it is that the .h file lives.
Click Done.
Clean and then Build.

renaming classes in iOS

I am working on Xcode 4.3.2 i wanted to rename my classes so i used refactor>rename, but after that i changed my mind and decided to go back to the older name. But when i do the same thing i've done before again, a warning dialog appears saying:
yourclass.h is not part of the build phase of any targets in this workspace and so can't be refactored. add the file to the build phase of a target in this workspace, or make a selection in another file.
what's the build phase? how can i solve this problem?
Thank you very much
It may be worthwhile to delete the projects derived data
Organizer --> Projects --> hit the delete derived data button for the project in question
Quit XCode
Open XCode
Build project. This will re-index your project and has been known to fix various environment issues such as
code sense
auto complete and
copmpiler targets
In Xcode, select your project at the top of the file tree on the left hand side.
From there, select your target, and click the "Build Phases" tab. Make sure the .m file of the class you're wanting to rename is listed under "Compile Sources"
You could check if you have the file here:
Targets => Select the target which is the select target your scheme is trying to run => Tab Build Phases => Compile Sources
Check if there is something wrong there (like file in red).
xCode usually takes snapshots when you rename the classes through the re-factor option .. you can go to File > restore SnapShote .. and choose the snapshot you want retrieve to and you will get back all the changed names.
In my case the .m file was under the compile sources. I did clear the project derived data and restarted xcode but to no avail.
I figured out though, that attempting to refactor the specific property in the .m file worked and renamed the property both in the header and the rest of the project references.

Resources