[MyTarget]-Swift.h does not have MySwiftClass declaration

19 Views Asked by At

On macOS CoreAudio plugin development, I try to call Swift func from Objective-C code. But I get error:

Use of undeclared identifier 'MySwiftClass'

I checked these.

  • Add "@objc" on Swift class and public func.
  • #import "[MyTarget]-Swift.h" on Objective-C code
  • On Xcode "Target Membership" of MySwiftClass.swift, MyTarget is checked.
  • Set Swift version to Swift5.
  • Set macOS min support to 12.3.
  • Run xcodebuild on command line and fixed all error

But "[MyTarget]-Swift.h" under ~/Library/Developer/Xcode/DerivedData/[MyProject]-[hash] has no declaration of MySwiftClass

I like to know command to generate [MyTarget]-Swift.h, and find out why MySwiftClass is ignored.

If target is macOS app, I can call Swift func from Objective-C code.

1

There are 1 best solutions below

0
user1418067 On

I found Xcode [Target]-Swift.h gen tool does not care about "Target Membership". It only see swift files under MyTarget directory.

Failed case files location

  • MyTarget1/MyOBJC1Class.m
  • MyTarget1/MySwiftClass.swift
  • MyTarget2/MyOBJC2Class.m
  • Xcode Target Membership of MySwiftClass.swift ON for MyTargert2

Success case files location

  • MyTarget1/MyOBJC1Class.m
  • MyTarget1/MySwiftClass.swift
  • MyTarget2/MyOBJC2Class.m
  • MyTarget2/MySwiftClass.swift (exact copy)