MCPcopy Create free account
hub / github.com/Tencent/MMKV / getObject

Method getObject

Core/MMKV_OSX.cpp:371–396  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

369}
370
371NSObject *MMKV::getObject(MMKVKey_t key, Class cls) {
372 if (isKeyEmpty(key) || !cls) {
373 return nil;
374 }
375 SCOPED_LOCK(m_lock);
376 SCOPED_LOCK(m_sharedProcessLock);
377 auto data = getDataForKey(key);
378 if (data.length() > 0) {
379 if (MiniPBCoder::isCompatibleClass(cls)) {
380 try {
381 auto result = MiniPBCoder::decodeObject(data, cls);
382 return result;
383 } catch (std::exception &exception) {
384 MMKVError("%s", exception.what());
385 } catch (...) {
386 MMKVError("decode fail");
387 }
388 } else {
389 if ([cls conformsToProtocol:@protocol(NSCoding)]) {
390 auto tmp = [NSData dataWithBytesNoCopy:data.getPtr() length:data.length() freeWhenDone:NO];
391 return unSecureUnArchiveObjectWithData(tmp);
392 }
393 }
394 }
395 return nil;
396}
397
398# ifndef MMKV_DISABLE_CRYPT
399

Callers

nothing calls this directly

Calls 2

isKeyEmptyFunction · 0.85

Tested by

no test coverage detected