Hello, I am pretty new to swift and objc development, and I am currently facing a problem :
I am building a project, in which I try to use a class defined in a swift file (myClass.swift),
into an objective-C++ file (usesMyClass.mm
).
To do so, I created a swift to objc header (myClass-Swift.h)
with the command
swiftc myClass.swift -emit-objc-header -emit-objc-header-path myClass-Swift.h
and included it into my objcpp file (#import "myClass-Swift.h"
).
Yet, when I compile, I get the following error :
Undefined symbols for architecture arm64: "_OBJC_CLASS_$__TtC16MyClass16Myclass", referenced from: objc-class-ref in usesMyClass.o
.
When I generated the -Swift.h
file, the command also generated a .swiftmodule
file, that I try to add to the project in Target->Build Phases->link binary with libraries, as I read that a .swiftmodule
was a binary, but I still got the error. I checked if the myClass.swift
file was correctly added to the sources of the project, and it was. I can't have the header in the target build as it is an App target, and the header is never used in the framework target.
Would anyone have an answer ?
N.B. : It seems the "Undefined symbols" error is pretty current but I have not found anything that matches exactly my problem and, thus, could help me get through it.