Skip to content

Instantly share code, notes, and snippets.

@bartlomiejn
bartlomiejn / CppClass.cpp
Created March 26, 2017 17:34
C++ class with C bridge definition file for swift-explorations.ghost.io
class CppClass {
public:
CppClass(const char* value) {
storedValue = value;
}
const char* storedValue;
};
extern "C" void* makeObject(const char* storedValue) {
return (void*) new CppClass(storedValue);
@bartlomiejn
bartlomiejn / CppClass.hpp
Created March 26, 2017 17:32
C bridge for C++ class example for swift-explorations.ghost.io
#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
@bartlomiejn
bartlomiejn / VideoFrame.swift
Last active March 26, 2017 19:54
Swift C struct usage example for swifty-explorations.ghost.io
let frame = VideoFrame(address: someAddress, width: 640, height: 480, stride: 8) // VideoFrame type
let frameWidth = frame.width // Int32 type
doSomethingWithFrame(frame: frame)
@bartlomiejn
bartlomiejn / VideoFrame.h
Last active March 26, 2017 17:42
C header file example for swift-explorations.ghost.io
typedef struct VideoFrameStruct {
void *address;
int width;
int height;
int stride;
} VideoFrame;
void doSomethingWithFrame(VideoFrame frame);