Skip to content

Instantly share code, notes, and snippets.

@bartlomiejn
Created March 26, 2017 17:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bartlomiejn/fd8f8d72a601d967e4d8bc647d94e499 to your computer and use it in GitHub Desktop.
Save bartlomiejn/fd8f8d72a601d967e4d8bc647d94e499 to your computer and use it in GitHub Desktop.
Swift wrapper for C bridge for swifty-explorations.ghost.io
final class SwiftCppClass {
private let cppClass: UnsafeMutableRawPointer
var storedValue: String! {
get {
guard
let currentValue = getStoredValue(cppClass),
let currentString = String(utf8String: currentValue)
else {
return nil
}
return currentString
} set {
setNewStoredValue(cppClass, (newValue as NSString).utf8String)
}
}
init(storedValue: String) {
cppClass = makeObject((storedValue as NSString).utf8String)
}
deinit {
removeObject(cppClass)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment