WIP: Talk to Swift via C without involving Objective-C

Co-Authored-By: Nathan Sobo <nathan@zed.dev>
This commit is contained in:
Antonio Scandurra
2022-09-13 14:10:13 +02:00
co-authored by Nathan Sobo
parent 5fec784580
commit 52f32b50b2
5 changed files with 60 additions and 47 deletions
-32
View File
@@ -1,32 +0,0 @@
//
// LKRoom.m
// LiveKitObjC
//
// Created by Antonio Scandurra on 01/09/22.
//
#import <Foundation/Foundation.h>
#import <LiveKitObjC-Swift.h>
@interface LKRoom: NSObject {
}
@property (nonatomic, retain) SLKRoom* room;
@end
@implementation LKRoom
-(id)init {
if (self = [super init]) {
self.room = [[SLKRoom alloc] init];
}
return self;
}
-(void)connectWithURL:(NSString *)url token:(NSString *)token callback:(void(^)(void))callback {
[self.room connectWithUrl:url token:token callback:callback];
}
@end
LKRoom* BuildLKRoom() {
return [[LKRoom alloc] init];
}
@@ -9,14 +9,12 @@
/* Begin PBXBuildFile section */
AFA4DBD628C0F839001AD7BE /* LiveKit in Frameworks */ = {isa = PBXBuildFile; productRef = AFA4DBD528C0F839001AD7BE /* LiveKit */; };
AFA4DBD928C0F87F001AD7BE /* Room.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFA4DBD828C0F87F001AD7BE /* Room.swift */; };
AFA4DBDB28C0FBC0001AD7BE /* LKRoom.m in Sources */ = {isa = PBXBuildFile; fileRef = AFA4DBDA28C0FBC0001AD7BE /* LKRoom.m */; };
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
AFA4DBCD28C0F7F5001AD7BE /* libLiveKitObjC.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libLiveKitObjC.a; sourceTree = BUILT_PRODUCTS_DIR; };
AFA4DBD728C0F87F001AD7BE /* LiveKitObjC-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "LiveKitObjC-Bridging-Header.h"; sourceTree = "<group>"; };
AFA4DBD828C0F87F001AD7BE /* Room.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Room.swift; sourceTree = "<group>"; };
AFA4DBDA28C0FBC0001AD7BE /* LKRoom.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LKRoom.m; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -34,7 +32,6 @@
AFA4DBC428C0F7F5001AD7BE = {
isa = PBXGroup;
children = (
AFA4DBDA28C0FBC0001AD7BE /* LKRoom.m */,
AFA4DBD828C0F87F001AD7BE /* Room.swift */,
AFA4DBCE28C0F7F5001AD7BE /* Products */,
AFA4DBD728C0F87F001AD7BE /* LiveKitObjC-Bridging-Header.h */,
@@ -124,7 +121,6 @@
buildActionMask = 2147483647;
files = (
AFA4DBD928C0F87F001AD7BE /* Room.swift in Sources */,
AFA4DBDB28C0FBC0001AD7BE /* LKRoom.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -245,13 +241,15 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
EXECUTABLE_PREFIX = lib;
KEEP_PRIVATE_EXTERNS = NO;
KEEP_PRIVATE_EXTERNS = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
PRESERVE_DEAD_CODE_INITS_AND_TERMS = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "LiveKitObjC-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
@@ -264,13 +262,15 @@
buildSettings = {
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEFINES_MODULE = YES;
EXECUTABLE_PREFIX = lib;
KEEP_PRIVATE_EXTERNS = NO;
KEEP_PRIVATE_EXTERNS = YES;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/../Frameworks",
"@loader_path/../Frameworks",
);
PRESERVE_DEAD_CODE_INITS_AND_TERMS = YES;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "LiveKitObjC-Bridging-Header.h";
SWIFT_VERSION = 5.0;
+24 -2
View File
@@ -8,10 +8,18 @@
import Foundation
import LiveKit
@objc public class SLKRoom: NSObject, RoomDelegate {
public class LKRoom: RoomDelegate {
lazy var room = Room(delegate: self)
@objc public func connect(
init() {
print("INIT!\n");
}
deinit {
print("DEINIT!\n");
}
public func connect(
url: String,
token: String,
callback: @convention(block) @escaping () -> Void
@@ -20,4 +28,18 @@ import LiveKit
callback()
}
}
}
@_cdecl("LKRoomCreate")
public func LKRoomCreate() -> UnsafeMutableRawPointer {
Unmanaged.passRetained(LKRoom()).toOpaque()
}
@_cdecl("LKRoomDestroy")
public func LKRoomDestroy(ptr: UnsafeRawPointer) {
let _ = Unmanaged<LKRoom>.fromOpaque(ptr).takeRetainedValue();
}