Xcode 11 XCFramework "... is not a member type of ..." error

Hi Guys,


i tried with the final Xcode 11 Version to generate a .xcframework from my framework but it will not work. I successfully generated the .xcframework like apple showed us on WWDC. But when i import the framework in a sample projekt, it throws the error: "Failed to load module ..." if i try to import it. And there are lot of errors from "arm64-apple-ios.swiftinterface". It's the same error for all public protocols, enums, structs


-> "... is not a member type of..."


This is the interface file where the errors appear and for every FastSocket.Struct, FastSocket.Protocol.. -> for example: "MessageProtocol is not a member type of FastSocket". I dont have any idea why this happen 😟. The Things are all public and the module works like expected. but not as xcframework 😟

// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)
// swift-module-flags: -target arm64-apple-ios13.0 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name FastSocket
import CryptoKit
import Foundation
import Network
import Swift
extension Data : FastSocket.MessageProtocol {
}
public protocol FastSocketProtocol : AnyObject {
  var on: FastSocket.FastSocketCallback { get set }
  var parameters: FastSocket.TransferParameters { get set }
  init(host: Swift.String, port: Swift.UInt16, type: FastSocket.TransferType)
  func connect()
  func disconnect()
  func send<T>(message: T) where T : FastSocket.MessageProtocol
}
public struct FastSocketCallback {
  public var ready: () -> Swift.Void
  public var close: () -> Swift.Void
  public var message: (FastSocket.MessageProtocol) -> Swift.Void
  public var bytes: (FastSocket.ByteCountResult) -> Swift.Void
  public var error: (Swift.Error?) -> Swift.Void
}
public protocol MessageTypeProtocol {
}
public protocol MessageProtocol {
}
public enum ByteCountResult {
  case input(Swift.Int)
  case output(Swift.Int)
}
extension String : FastSocket.MessageProtocol {
}
public enum TransferType {
  case tcp
  case tls
  public static func == (a: FastSocket.TransferType, b: FastSocket.TransferType) -> Swift.Bool
  public var hashValue: Swift.Int {
    get
  }
  public func hash(into hasher: inout Swift.Hasher)
}
public class FastSocket : FastSocket.FastSocketProtocol {
  public var on: FastSocket.FastSocketCallback
  public var parameters: FastSocket.TransferParameters
  required public init(host: Swift.String, port: Swift.UInt16, type: FastSocket.TransferType = .tcp)
  public func connect()
  public func disconnect()
  public func send<T>(message: T) where T : FastSocket.MessageProtocol
  @objc deinit
}
public struct TransferParameters {
  public var acceptLocalOnly: Swift.Bool
  public var allowFastOpen: Swift.Bool
  public var preferNoProxies: Swift.Bool
  public var prohibitedInterfaceTypes: [Network.NWInterface.InterfaceType]
  public var prohibitExpensivePaths: Swift.Bool
  public var requiredInterfaceType: Network.NWInterface.InterfaceType
  public var serviceClass: Network.NWParameters.ServiceClass
  public var multipathServiceType: Network.NWParameters.MultipathServiceType
}
public enum FastSocketError : Swift.Int, Swift.Error {
  case none
  case emptyHost
  case handshakeInitializationFailed
  case handshakeVerificationFailed
  case timeoutError
  case networkUnreachable
  case sendFailed
  case sendToEarly
  case socketClosed
  case socketUnexpectedClosed
  case writeBeforeClear
  case parsingFailure
  case zeroData
  case readBufferIssue
  case readBufferOverflow
  case writeBufferOverflow
  case unknownOpcode
  public typealias RawValue = Swift.Int
  public init?(rawValue: Swift.Int)
  public var rawValue: Swift.Int {
    get
  }
}
extension FastSocketError {
  public static var errorDomain: Swift.String {
    get
  }
  public var errorCode: Swift.Int {
    get
  }
  public var errorUserInfo: [Swift.String : Swift.String] {
    get
  }
}
extension FastSocket.TransferType : Swift.Equatable {}
extension FastSocket.TransferType : Swift.Hashable {}
extension FastSocket.FastSocketError : Swift.Equatable {}
extension FastSocket.FastSocketError : Swift.Hashable {}
extension FastSocket.FastSocketError : Swift.RawRepresentable {}


i generated it with the following commands and i also set the Build Library for Distribution to Yes


xcodebuild archive -scheme FastSocket -destination generic/platform=iOS -archivePath ./FastSocket.xcarchive SKIP_INSTALL=NO BUILD_LIBRARIES_FOR_DISTRIBUTION=YES
xcodebuild -create-xcframework -framework FastSocket.xcarchive/Products/Library/Frameworks/FastSocket.framework -output FastSocket.xcframework

I ran into the same issue.


The problem is that in the Swiftinterface file, you have a class named FastSocket, but the module is also called FastSocket. The generated file includes many module references that Swift thinks are class references because it uses the class ahead of the module...


There is a workaround, edit all of the .swiftinterface files to remove the module references (FastSocket.). There are many .swiftinterface files (one per architecture supported) so an easy way to do them all at once is to run this in the root of the .xcframework directory:
find . -name "*.swiftinterface" -exec sed -i -e 's/FastSocket\.//g' {} \;
You may want to check that has only removed module references, in the case where you have some subelements of the FastSocket class that might need more refining to get right.


After running that do a clean build of a project using that framework and try again, the erorrs should be gone.
Apple is working on a fix for this so before too long hopefully this step of XCFramework generation will not be required.

Accepted Answer

I ran into the same issue.


The problem is that in the Swiftinterface file, you have a class named FastSocket, but the module is also called FastSocket. The generated file includes many module references that Swift thinks are class references because it uses the class ahead of the module...


There is a workaround, edit all of the .swiftinterface files to remove the module references (FastSocket.). There are many .swiftinterface files (one per architecture supported) so an easy way to do them all at once is to run this in the root of the .xcframework directory:
find . -name "*.swiftinterface" -exec sed -i -e 's/FastSocket\.//g' {} \;
You may want to check that has only removed module references, in the case where you have some subelements of the FastSocket class that might need more refining to get right.


After running that do a clean build of a project using that framework and try again, the erorrs should be gone.
Apple is working on a fix for this so before too long hopefully this step of XCFramework generation will not be required.

11

Are there any updates on this? The problem still exists. However, your solution works fine.

Any updates on this bug ? Do you have a bugs.swift.org link related to this one ?

just Add "-no-verify-emitted-module-interface" to Other Swift Flags to your Build Settings if you are using SPM or Cocoapods.

Xcode 11 XCFramework "... is not a member type of ..." error
 
 
Q