Piasy
12/10/2019, 4:27 AMabstract class ConfEvents {
open fun onPeerJoined(uid: String) {}
}
Here is the generated C header:
struct {
libAvConf_KType* (*_type)(void);
libAvConf_kref_com_piasy_avconf_ConfEvents (*ConfEvents)();
void (*onPeerJoined)(libAvConf_kref_com_piasy_avconf_ConfEvents thiz, const char* uid);
} ConfEvents;
If I compile kotlin code into framework, then ConfEvents
would have a Objective-C interface, then I can extend it and pass it to kotlin.Cristián Arenas
12/10/2019, 6:59 PMlibAvConf_kref_com_piasy_avconf_ConfEvents
, which it would get by calling privateInstance = ConfEvents.ConfEvents()
on the wrapper’s constructor, and then I would reimplement every method, like -(void)onPeerJoined(const char* uid)
and it would call the correct one inside ConfEvents.onPeerJoined(privateInstance, uid)
Piasy
12/11/2019, 2:49 AMConfEvents
class in Objective-C, and its method will be called at kotlin code, and I need pass that Objective-C object to a kotlin method which receive a ConfEvents
object.
That kotlin method is:
fun create(
uid: String,
events: ConfEvents
): AvConf
And the generated C API is:
libAvConf_kref_com_piasy_avconf_AvConf (*create)(libAvConf_kref_com_piasy_avconf_AvConf_Companion thiz, const char* uid, libAvConf_kref_com_piasy_avconf_ConfEvents events);
In your description, it seems to wrap a kotlin object with an Objective-C object, and use it in Objective-C, am I right?Cristián Arenas
12/11/2019, 12:56 PMIn your description, it seems to wrap a kotlin object with an Objective-C object, and use it in Objective-C, am I right?Yes, that’s the idea. I do not yet know how to create an Objective-C header when creating a static library, so wrapping the C API in an Objective-C class would solve some of your problems. After wrapping all the methods, you can subclass that class in Objective-C, the only difference would be that if any function requires a pointer to the original
ConfEvents
class, you would have to pass it the inner private instance (of type libAvConf_kref_com_piasy_avconf_ConfEvents
).
The better solution would be to ask how to generate the static library with an Objective-C API, I have no idea how to do thatPiasy
12/11/2019, 1:01 PMonPeerJoined
function of ConfEvents
is called in kotlin code, how could the Objective-C code be called?Cristián Arenas
12/11/2019, 1:02 PMPiasy
12/11/2019, 1:10 PMso wrapping the C API in an Objective-C classYou mean I can create an Objective-C class, e.g.
ObjCConfEvents
, it will own a pointer of libAvConf_kref_com_piasy_avconf_ConfEvents
, and its onPeerJoined
method will call void (*onPeerJoined)(libAvConf_kref_com_piasy_avconf_ConfEvents thiz, const char* uid);
, then I can create subclass of ObjCConfEvents
, e.g. SpecialConfEvents
, and doing the real logic in its onPeerJoined
method, right?
the only difference would be that if any function requires a pointer to the originalYou mean I need pass theclass, you would have to pass it the inner private instance (of typeConfEvents
)libAvConf_kref_com_piasy_avconf_ConfEvents
libAvConf_kref_com_piasy_avconf_ConfEvents
of ObjCConfEvents
to kotlin code (the create
function), right?
If my understanding is correct, when kotlin code call onPeerJoined
of libAvConf_kref_com_piasy_avconf_ConfEvents
, how could the ObjCConfEvents
get called?
Sorry if my understanding is wrong, and please correct me if so.
Thank you very much!Cristián Arenas
12/11/2019, 1:13 PMPiasy
12/11/2019, 1:14 PMCristián Arenas
12/11/2019, 1:15 PMPiasy
12/11/2019, 1:18 PMCristián Arenas
12/11/2019, 1:19 PMPiasy
12/11/2019, 1:21 PMCristián Arenas
12/11/2019, 1:22 PMPiasy
12/11/2019, 1:24 PMCristián Arenas
12/11/2019, 1:25 PMDon’t Create Umbrella Frameworks
While it is possible to create umbrella frameworks using Xcode, doing so is unnecessary for most developers and is not recommended. Apple uses umbrella frameworks to mask some of the interdependencies between libraries in the operating system. In nearly all cases, you should be able to include your code in a single, standard framework bundle. Alternatively, if your code was sufficiently modular, you could create multiple frameworks, but in that case, the dependencies between modules would be minimal or nonexistent and should not warrant the creation of an umbrella for them.
Piasy
12/11/2019, 1:26 PMCristián Arenas
12/11/2019, 1:27 PMPiasy
12/11/2019, 1:28 PMCristián Arenas
12/11/2019, 1:29 PMcodesign
command line tool.
f="$CODESIGNING_FOLDER_PATH/Frameworks/YourOuterFrameworkName.framework/Frameworks/YourInnerFrameworkName.framework"
codesign --force --sign "$EXPANDED_CODE_SIGN_IDENTITY_NAME" --preserve-metadata=identifier,entitlements --timestamp=none "$f"
That way the app project only needs to depend on the outer onePiasy
12/11/2019, 1:31 PMCristián Arenas
12/11/2019, 1:31 PMPiasy
12/11/2019, 1:32 PMCristián Arenas
12/11/2019, 1:32 PMPiasy
12/11/2019, 1:33 PMCristián Arenas
12/11/2019, 1:35 PMPiasy
12/11/2019, 1:38 PMArtyom Degtyarev [JB]
12/12/2019, 8:37 AM