Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode 12: 'SessionDelegate' has different definitions in different modules

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
like image 526
Feridun Erbaş Avatar asked Aug 27 '20 10:08

Feridun Erbaş


People also ask

Has different definitions in different modules first difference is definition in?

'Thing' has different definitions in different modules; first difference is definition in module 'FrameworkOne.Swift' found method name 'doSomething'

What are Xcode modules?

Module: A set of parts that can be assembled into a structure. To Xcode, that means you can have a group of lines of code that you can (re)use in different places without having to write that code again.

How to fix sessiondelegate error in Xcode 12?

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. Show activity on this post.

What is the difference between'sessiondelegate'and'session Delegate'in different modules?

'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. Is there any way to edit header files to have different names for SessionDelegate for Alamofire or Kingfisher?

Can different modules have the same name in Xcode?

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.

Is this still happening on Xcode 12 GM seed?

I can confirm that this is still happening on Xcode 12 GM seed. Issue is still present on the released non-beta Xcode 12. Same here. I had to force rename one of third-party class name...


Video Answer


4 Answers

You can try SWIFT_INSTALL_OBJC_HEADER = NO, it works for me

enter image description here

like image 83
sam Avatar answered Oct 19 '22 07:10

sam


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

like image 24
Simon I. Avatar answered Oct 19 '22 06:10

Simon I.


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.

like image 1
Senocico Stelian Avatar answered Oct 19 '22 05:10

Senocico Stelian


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'

like image 1
Feridun Erbaş Avatar answered Oct 19 '22 05:10

Feridun Erbaş