Created
March 26, 2017 17:37
-
-
Save bartlomiejn/fd8f8d72a601d967e4d8bc647d94e499 to your computer and use it in GitHub Desktop.
Swift wrapper for C bridge for swifty-explorations.ghost.io
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 { | |
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