28

Edit: This problem occurs after XCode 12 Beta5. Xcode doesn't allow different modules to define same names (Probably for public classes & protocols). Alamofire and Kingfisher appears to define SessionDelegate at the same time. I'm still trying to find a solution..

I'm implementing iOS 14 Widgets in our application. I have started working with XCode 12 Beta 2 and everthing was compiling fine. When I have updated XCode to XCode 12 Beta 6, I faced with following error:

'SessionDelegate' has different definitions in different modules; first difference is definition in module 'Kingfisher.Swift' found end of class

I'm also attaching the screenshot of the file with error.

enter image description here

Is there any way to edit header files to have different names for SessionDelegate for Alamofire or Kingfisher? Is there any workaround to overcome this issue?

Here are things I have tried so far:

  • I have updated both Alamofire and Kingfisher to latest version
  • I have cleaned Podfile.lock and all pods as well as Derived Data
  • I tried to compile with Legacy Build System
Feridun Erbaş
  • 425
  • 6
  • 18
  • I have edited my question accordingly @matt – Feridun Erbaş Aug 27 '20 at 12:59
  • 2
    You would need to complain to the pod authors. Objective C has no namespaces, so you are supposed to give your types unique names using prefixing. They didn’t. That was dumb but there’s nothing _you_ can do about it. Unless you want to just change their code, which is not a very robust approach because an update will wipe out your changes. – matt Aug 27 '20 at 13:24
  • 2
    From the code posted, it's apparent Kingfisher tried to provide a mangled Swift name which does provide the namespace. Perhaps there's an issue with this approach in Xcode 12. @FeridunErbaş you should file a bug with Kingfisher about this to see if they can fix it. In the meantime you can fork the library and do your own rename. – Jon Shier Aug 27 '20 at 18:24
  • 1
    @JonShier Alamofire and Kingfisher are conflicting actually. I will file a bug to both of them – Feridun Erbaş Aug 27 '20 at 22:43
  • That bug will be closed for Alamofire, since there's nothing for us to do there. Swift has namespacing, so there's no need for the type prefix that Obj-C needs. – Jon Shier Aug 28 '20 at 02:45
  • The issue happens if one of the frameworks is an ObjC framework. If you have swift frameworks only - everything works fine. – Sandr Sep 01 '20 at 16:53
  • @SlippD.Thompson Plus, my _second_ comment (now the first), made after the question was improved, is in fact the correct answer. So really there is nothing wrong about how the conversation went. – matt Nov 26 '20 at 17:08

4 Answers4

18

You can try SWIFT_INSTALL_OBJC_HEADER = NO, it works for me

enter image description here

sam
  • 189
  • 3
  • 2
    Can you make your answer a little bid more specific? From where exactly should we change this flag? – Feridun Erbaş Sep 17 '20 at 13:49
  • 3
    Go to Project, Build Settings, select All tab, search for SWIFT_INSTALL_OBJC_HEADER, and change its value to NO. Anyway, it's not working. – Senocico Stelian Sep 18 '20 at 10:22
  • This worked for me, you just do this step under the framework setting not in your project target – Pankaj Sonava Oct 07 '20 at 09:15
  • thank you , this worked for me under framework setting , good hint @PankajSonava – taha Oct 15 '20 at 12:40
  • @PankajSonava hey just wondering how do i manage to do this under the framework setting instead of in the project target? because i can't get this solved – llehcram Oct 18 '20 at 11:35
  • 3
    Hey @llehcram follow these steps :- 1. Click on Pods from your Xcode Project Navigator. 2. There are you can see the list of framework you attached with project. 3. Then you select the framework which show this error. 4. Under this framework setting you need to do this steps – Pankaj Sonava Oct 19 '20 at 06:04
14

At this moment (Xcode 12.0 or Xcode 12.2b2), the only possible solution is to rename the Objective-C interface and avoid conflicts. This could be done by one of:

  • Rename conflicting class entirely, update all places where it's used (e.g. replace SessionDelegate by KingfisherSessionDelegate)
  • Add @objc(...) attribute to a Swift class, which will update the Obj-C interface in a generated ...-Swift.h file and avoid the names conflict.
//  SessionDelegate.swift
@objc(KFSessionDelegate)
class SessionDelegate: NSObject { ... }
//  Kingfisher-Swift.h
@interface KFSessionDelegate : NSObject
...
@end

This solution is already included in the Kingfisher 5.15.4 release and could be applied to any other libraries and your own frameworks.

Also, the thread on Apple forums: https://developer.apple.com/forums/thread/658012

Simon I.
  • 306
  • 1
  • 4
1

The error is saying that you have multiple classes with the same name SessionDelegate in different modules. This error is related to Xcode 12.

For now, a quick solution is to install the module with CocoaPods (if you're using Carthage) and if needed, rename the SessionDelegate interface.

Senocico Stelian
  • 637
  • 7
  • 18
1

If you guys need a temporary solution, here is how for Cocoapods users:

  1. Clone the Kingfisher library to the same folder level with your project. You can get it from Github

  2. Open Kingfisher.xcworkspace in XCode and rename SessionDelegate.swift file under Sources/Netowking to KingFisherSessionDelegate and change the class name as well accordingly.

  3. Rename the usages of SessionDelegate to KingfisherSessionDelegate which is only available in Sources/Networking/ImageDownloader.swift as of Kingfisher version 5.15.0

  4. Add local path in your Podfile

    pod 'Kingfisher', :path => '../Kingfisher'

Feridun Erbaş
  • 425
  • 6
  • 18