Integrate Objective-C in Swift
It's my first time working with Objective-C, primarily because I need to utilize the bare runtime environment for developing P2P applications using the hypercore protocol
So, this video on YT helped me get integrating bridging header.
Steps to follow:
1. Create a header file objc-bridge.h
2. Go to Build Settings -> Search for Bridging -> Add the path -> Like Below
- Build the project that's it.
//
// objc-bridge-header.h
// Hello_World
//
// Created by JJ on 2024-07-10.
//
#ifndef objc_bridge_header_h
#define objc_bridge_header_h
#import <Foundation/Foundation.h>
#if DEBUG
static inline void printBridgingHeaderMessage() {
NSLog(@"Bridging header included successfully.");
}
#endif
#endif /* objc_bridge_header_h */
//
// ContentView.swift
// Hello_World
//
// Created by JJ on 2024-07-10.
//
import SwiftUI
import Foundation
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.padding()
.onAppear {
#if DEBUG
printBridgingHeaderMessage()
#endif
}
}
}
#Preview {
ContentView()
}
So yeah, it does work like C which is fine to me. However, not yet done because we need to call bare side of code. So going to try then let you know on another post.