This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifdef __cplusplus | |
extern "C" { | |
#endif | |
void* makeObject(const char* storedValue); | |
void setNewStoredValue(void* object, const char* newValue); | |
const char* getStoredValue(void* object); | |
void removeObject(void* object); | |
#ifdef __cplusplus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CppClass { | |
public: | |
CppClass(const char* value) { | |
storedValue = value; | |
} | |
const char* storedValue; | |
}; | |
extern "C" void* makeObject(const char* storedValue) { | |
return (void*) new CppClass(storedValue); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CppClass { | |
public: | |
CppClass(const char* value) { | |
storedValue = value; | |
} | |
const char* storedValue; | |
}; | |
extern "C" void* makeObject(const char* storedValue) { | |
return (void*) new CppClass(storedValue); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class SwiftCppClass { | |
private let cppClass: UnsafeMutableRawPointer | |
var storedValue: String! { | |
get { | |
guard | |
let currentValue = getStoredValue(cppClass), | |
let currentString = String(utf8String: currentValue) | |
else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface CppClassWrapper : NSObject | |
@property (nonatomic, copy) NSString* _Nonnull storedValue; | |
- (instancetype)initWithStoredValue:(NSString* _Nonnull)value; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface CppClassWrapper () | |
@property (nonatomic) CppClass* cppClass; | |
@end | |
@implementation CppClassWrapper | |
- (void)setStoredValue:(NSString*) storedValue { | |
self.cppClass->storedValue = [storedValue UTF8String]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
typedef struct VideoFrameStruct { | |
void *address; | |
int width; | |
int height; | |
int stride; | |
} VideoFrame; | |
void doSomethingWithFrame(VideoFrame frame); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cppClass = CppClassWrapper(storedValue: „Some value”)! | |
print(cppClass.storedValue) // Some value | |
cppClass.storedValue = „New value” | |
print(cppClass.storedValue) // New value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let object = makeObject(("Value" as NSString).utf8String) // UnsafeMutableRawPointer? type | |
setNewStoredValue(object, ("New value" as NSString).utf8String) | |
print(String(cString: getStoredValue(object))) // New value | |
removeObject(object) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let frame = VideoFrame(address: someAddress, width: 640, height: 480, stride: 8) // VideoFrame type | |
let frameWidth = frame.width // Int32 type | |
doSomethingWithFrame(frame: frame) |
OlderNewer