Renato Stauffer
Renato Stauffer

Reputation: 813

Two Objective C files with the same name in different targets, used by Swift class

The situation is as followed: I have two targets (A and B) and they contain a class with the same name but different implementations (let's call these classes Hello.m and Hello.h). So:

Target A contains Hello.m and Hello.h
Target B contains Hello.m and Hello.h (different implementation with different properties)

Now I have a swift class called Consumer.swift only in target B. This class would need to use the Hello.m and Hello.h of target B. But somehow Xcode tries to include the class / header of target A, which leads to the following error: Value of type 'Hello' has no member 'propertyOnlyAvailableInTargetB'

Has anyone an idea how I can tell the swift class to use the right class / header from the right target? Why would Xcode like to use the Hello.m and Hello.h of target A instead of B?

I tried to set the "Header Search Paths" in the Build Settings to the specific folders in the project and I set the "Use Header Maps" to false. After setting this flag I get the error "Failed to import bridging header...Bridging-Header.h", since the folder structure looks like this:

Project

Any answers would be appreciated :) Thx!

Upvotes: 1

Views: 1559

Answers (1)

Darren
Darren

Reputation: 25619

Your file system hierarchy and your Xcode project hierarchy should look like this:

Project
   |-- Bridging-Header.h
   |
   |-- FolderA
   |      |-- Hello.h
   |      |-- Hello.m
   |
   |-- FolderB
          |-- Hello.h
          |-- Hello.m

When importing a file to the bridging header, specify the folder name:

#import "FolderB/Hello.h"

If you move your bridging header, you'll need to update your project settings to point to the new path. Open the build settings, search for "bridging", then update the path.

Upvotes: 4

Related Questions