first commit
This commit is contained in:
commit
e2c095af41
34 changed files with 667 additions and 0 deletions
20
objc/MyClass.h
Normal file
20
objc/MyClass.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
// swift/MyClass.h
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Declare functions to be used by Rust
|
||||
void create_object();
|
||||
void call_method();
|
||||
const char* get_message();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@interface MyClass : NSObject
|
||||
- (void)printMessage;
|
||||
- (NSString *)getMessage;
|
||||
@end
|
35
objc/MyClass.m
Normal file
35
objc/MyClass.m
Normal file
|
@ -0,0 +1,35 @@
|
|||
// swift/MyClass.m
|
||||
#import "MyClass.h"
|
||||
|
||||
@implementation MyClass
|
||||
|
||||
- (void)printMessage {
|
||||
NSLog(@"Hello from Objective-C!");
|
||||
}
|
||||
|
||||
- (NSString *)getMessage {
|
||||
return @"Hello from Objective-C!";
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// C-compatible interface functions
|
||||
static MyClass *myClassInstance = nil;
|
||||
|
||||
void create_object() {
|
||||
myClassInstance = [[MyClass alloc] init];
|
||||
}
|
||||
|
||||
void call_method() {
|
||||
if (myClassInstance) {
|
||||
[myClassInstance printMessage];
|
||||
}
|
||||
}
|
||||
|
||||
const char* get_message() {
|
||||
if (myClassInstance) {
|
||||
NSString *message = [myClassInstance getMessage];
|
||||
return [message UTF8String];
|
||||
}
|
||||
return "";
|
||||
}
|
6
objc/objc_wrapper.h
Normal file
6
objc/objc_wrapper.h
Normal file
|
@ -0,0 +1,6 @@
|
|||
#ifndef OBJC_WRAPPER_H
|
||||
#define OBJC_WRAPPER_H
|
||||
|
||||
void call_objc_function();
|
||||
|
||||
#endif // OBJC_WRAPPER_H
|
7
objc/objc_wrapper.m
Normal file
7
objc/objc_wrapper.m
Normal file
|
@ -0,0 +1,7 @@
|
|||
#import "objc_wrapper.h"
|
||||
#import "MyClass.h"
|
||||
|
||||
void call_objc_function() {
|
||||
MyClass *obj = [[MyClass alloc] init];
|
||||
[obj helloFromObjectiveC];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue