Saty
Saty

Reputation: 2621

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.

Upvotes: 7

Views: 6370

Answers (3)

Krunal
Krunal

Reputation: 79726

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

> Test

Create new file with multiple targets
Menu >> New File >> Select File Type >> Assign File Name >> Next >> Select targets for your file.

x

Upvotes: 5

xiangxin
xiangxin

Reputation: 409

Have you tried removing the Module and select Inherit From Target instead?

enter image description here

Upvotes: 0

Alex
Alex

Reputation: 1245

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. targets

Upvotes: 5

Related Questions