Xcode 12 different definitions in different modules build error

In the Xcode 12 betas I'm seeing an issue with importing Swift modules with @objc annotations.

Given two Swift modules which expose classes of the same name:

Code Block
// FrameworkOne
@objc
public class Thing: NSObject {
public override init() {}
@objc
public func doSomething() {}
}


Code Block
// FrameworkTwo
@objc
public class Thing: NSObject {
public override init() {}
@objc
public func doSomethingElse() {}
}


And if I have imported both of the frameworks into an ObjC file and interact with the classes in either of them:

Code Block
#import <Foundation/Foundation.h>
@import FrameworkOneObjC;
@import FrameworkTwoObjC;
@interface Example : NSObject
@end
@implementation Example
- (void) example
{
Thing *thing = [[Thing alloc] init];
}
@end


Then I'm seeing this build error:
Code Block
'Thing' has different definitions in different modules; first difference is definition in module 'FrameworkOne.Swift' found method name 'doSomething'
But in 'FrameworkTwo.Swift' found method name 'doSomethingElse'


Is this expected behaviour? If so, is there any way to opt out?

In my case FrameworkOne & FrameworkTwo are external dependencies, and I'm unable to change the names of the classes.
Post not yet marked as solved Up vote post of mike-velu Down vote post of mike-velu
21k views

Replies

Is there any solution to this? Please do it quickly! Please do it quickly ! Please do it quickly
We do not use any obj-c code in our project, so our solution was to set the
Code Block
SWIFT_INSTALL_OBJC_HEADER
build setting to 'NO' for all the pods in the post_install hook of cocoapods.
This is incredibly frustrating. To be honest most iOS development is incredibly frustrating but I don't understand why third party developers making silly mistakes should bite my project in the behind when upgrading to the latest version of XCode.

It sucks that Obj-C doesn't have namespacing and that third party devs didn't prefix, but how come this issue was avoided in previous XCode versions?

My build is completely broken now.
为什么不解决?为什么到现在还没解决?xcode 真的太差了,开发人员都干什么吃的?

Why not fix it? why not fix it now? Xcode is so bad, what do developers do for a living?
the same to me
please resolve quickly
Workaround
  • Both classes are in same workspace, rename one of the class name and it will resolve problem.

  • Both classes are in frameworks, fork one of the repos and rename class name and use fork repo instead of actual repo, it will resolve problem.

In general, you have to rename one of the class name in order to run your project. You just have to think about how to rename them based upon your project settings.
Why not fix it? why not fix it now
Is there any solution to this? Please do it quickly! Please do it quickly ! Please do it quickly
Has this issue been fixed?
I am still facing it in Xcode 12.3.
DELETED REPLY
check whether the header file name is repeated,remove the file which is not used. Doing this helped in my case.
Is there any update from Apple on this issue?

I am still facing it in Xcode 12.5.1 Is there any update from Apple on this issue?

If you are using Cocoapods, this previous post worked well for our project:

We do not use any obj-c code in our project, so our solution was to set the Code Block

SWIFT_INSTALL_OBJC_HEADER

build setting to 'NO' for all the pods in the post_install hook of cocoapods.

Here is an example – at the end of our Podfile:

# CocoaPods With conflicting symbol nameds 
PodsWithConflictingSymbolNames = [
  'CognoaUIKit',
  'Macaw',
]

## Pods settings.
post_install do |installer|
    installer.generated_projects.each do |project|
        project.targets.each do |target|
            if PodsWithConflictingSymbolNames.include? target.name
                target.build_configurations.each do |config|
                    config.build_settings['SWIFT_INSTALL_OBJC_HEADER'] = 'NO'
                end
            end
        end
    end
end