C++
std::shared_ptr FSOCache::copyPtr(const std::string& path) {
std::lock_guard<std::mutex> guard(cacheMutex);
auto it = cache.find(path);
if (it == cache.end()) {
return nullptr;
}
auto p = std::make_shared<FSObject>(it->second);
return p;
}
std::shared_ptr FSOManager::getFSO(const std::string& path) {
auto fso = fsoCache.copyPtr(path);
return fso;
};
Swift
var m = FSOManager()
let cxxp = std.string(somePath)
var fsoPtr = m.getFSO(cxxp)
if fsoPtr == nil {
}
Using if fsoPtr == nil {} gives the warning 'Comparing non-optional value of type 'std.__1.shared_ptr' to 'nil' always returns false'.
fsoPtr.pointee does not return a pointer.