78 if (
self.storageManager == nil) {
79 NSLog(
@"StorageManager not initialized");
86 NSLog(
@"Existing storages: %@", storageList);
92 NSLog(
@"Created test storage");
98 NSLog(
@"Updated storage list: %@", updatedList);
103 NSLog(
@"Removed test storage");
107 NSLog(
@"Final storage list: %@", finalList);
114 if (
self.userStorage == nil) {
115 NSLog(
@"User storage not initialized");
119 NSLog(
@"\n=== KeyValueStorage Methods Demonstration ===");
123 [
self.
userStorage putString:@"user_name" value:@"John Doe"];
124 [
self.
userStorage putString:@"user_email" value:@"john.doe@example.com"];
125 NSLog(
@"Stored string values");
132 NSLog(
@"Stored integer values");
137 [
self.
userStorage putLong:@"registration_timestamp" value:1640995200000LL];
138 [
self.
userStorage putLong:@"last_login_timestamp" value:(long long)[[
NSDate date] timeIntervalSince1970] * 1000];
139 NSLog(
@"Stored long values");
144 [
self.
userStorage putBool:@"is_premium" value:YES];
145 [
self.
userStorage putBool:@"notifications_enabled" value:NO];
146 NSLog(
@"Stored boolean values");
151 [
self.
userStorage putFloat:@"user_rating" value:4.5f];
152 [
self.
userStorage putFloat:@"temperature" value:23.5f];
153 NSLog(
@"Stored float values");
158 [
self.
userStorage putDouble:@"user_location_lat" value:55.7558];
159 [
self.
userStorage putDouble:@"user_location_lng" value:37.6176];
160 NSLog(
@"Stored double values");
165 BOOL hasUserName = [
self.
userStorage contains:@"user_name"];
166 BOOL hasNonExistent = [
self.
userStorage contains:@"non_existent_key"];
167 NSLog(
@"Contains 'user_name': %@", hasUserName ?
@"YES" :
@"NO");
168 NSLog(
@"Contains 'non_existent_key': %@", hasNonExistent ?
@"YES" :
@"NO");
174 NSLog(
@"All stored keys: %@", allKeys);
179 NSString *userName = [
self.
userStorage getString:@"user_name" defaultValue:@"Unknown"];
180 NSString *userEmail = [
self.
userStorage getString:@"user_email" defaultValue:@""];
181 NSString *nonExistent = [
self.
userStorage getString:@"non_existent_key" defaultValue:@"default_value"];
182 NSLog(
@"User name: %@", userName);
183 NSLog(
@"User email: %@", userEmail);
184 NSLog(
@"Non-existent key: %@", nonExistent);
189 int32_t userAge = [
self.
userStorage getInt:@"user_age" defaultValue:0];
190 int32_t loginCount = [
self.
userStorage getInt:@"login_count" defaultValue:0];
191 int32_t nonExistentInt = [
self.
userStorage getInt:@"non_existent_int" defaultValue:-1];
192 NSLog(
@"User age: %d", userAge);
193 NSLog(
@"Login count: %d", loginCount);
194 NSLog(
@"Non-existent int: %d", nonExistentInt);
199 int64_t regTimestamp = [
self.
userStorage getLong:@"registration_timestamp" defaultValue:0];
200 int64_t lastLogin = [
self.
userStorage getLong:@"last_login_timestamp" defaultValue:0];
201 int64_t nonExistentLong = [
self.
userStorage getLong:@"non_existent_long" defaultValue:-1];
202 NSLog(
@"Registration timestamp: %lld", regTimestamp);
203 NSLog(
@"Last login timestamp: %lld", lastLogin);
204 NSLog(
@"Non-existent long: %lld", nonExistentLong);
209 BOOL isPremium = [
self.
userStorage getBool:@"is_premium" defaultValue:NO];
210 BOOL notificationsEnabled = [
self.
userStorage getBool:@"notifications_enabled" defaultValue:YES];
211 BOOL nonExistentBool = [
self.
userStorage getBool:@"non_existent_bool" defaultValue:NO];
212 NSLog(
@"Is premium: %@", isPremium ?
@"YES" :
@"NO");
213 NSLog(
@"Notifications enabled: %@", notificationsEnabled ?
@"YES" :
@"NO");
214 NSLog(
@"Non-existent bool: %@", nonExistentBool ?
@"YES" :
@"NO");
219 float userRating = [
self.
userStorage getFloat:@"user_rating" defaultValue:0.0f];
220 float temperature = [
self.
userStorage getFloat:@"temperature" defaultValue:0.0f];
221 float nonExistentFloat = [
self.
userStorage getFloat:@"non_existent_float" defaultValue:-1.0f];
222 NSLog(
@"User rating: %f", userRating);
223 NSLog(
@"Temperature: %f", temperature);
224 NSLog(
@"Non-existent float: %f", nonExistentFloat);
229 double userLat = [
self.
userStorage getDouble:@"user_location_lat" defaultValue:0.0];
230 double userLng = [
self.
userStorage getDouble:@"user_location_lng" defaultValue:0.0];
231 double nonExistentDouble = [
self.
userStorage getDouble:@"non_existent_double" defaultValue:-1.0];
232 NSLog(
@"User location lat: %f", userLat);
233 NSLog(
@"User location lng: %f", userLng);
234 NSLog(
@"Non-existent double: %f", nonExistentDouble);
241 NSLog(
@"Removed 'user_age' key");
245 BOOL stillHasAge = [
self.
userStorage contains:@"user_age"];
246 NSLog(
@"Still contains 'user_age': %@", stillHasAge ?
@"YES" :
@"NO");
251 NSLog(
@"Cleared all data from user storage");
256 NSLog(
@"Keys after clear: %@", keysAfterClear);
263 if (
self.userStorage == nil ||
self.appStorage == nil ||
self.cacheStorage == nil) {
264 NSLog(
@"Storages not initialized");
268 NSLog(
@"\n=== Multiple Storages Demonstration ===");
271 [
self.
userStorage putString:@"name" value:@"John Doe"];
273 [
self.
userStorage putBool:@"is_premium" value:YES];
275 [
self.
appStorage putString:@"theme" value:@"dark"];
276 [
self.
appStorage putInt:@"api_version" value:2];
277 [
self.
appStorage putBool:@"debug_mode" value:NO];
279 [
self.
cacheStorage putLong:@"last_update" value:(long long)[[
NSDate date] timeIntervalSince1970] * 1000];
280 [
self.
cacheStorage putString:@"api_token" value:@"abc123"];
281 [
self.
cacheStorage putDouble:@"cached_rating" value:4.2];
284 NSLog(
@"User storage data:");
285 [
self demonstrateStorageData:
self.userStorage];
287 NSLog(
@"\nApp storage data:");
288 [
self demonstrateStorageData:
self.appStorage];
290 NSLog(
@"\nCache storage data:");
291 [
self demonstrateStorageData:
self.cacheStorage];
349 if (
self.storageManager == nil) {
350 NSLog(
@"StorageManager not initialized");
354 NSLog(
@"\n=== Storage Analytics ===");
358 NSLog(
@"Total storages: %lu", (
unsigned long)allStorages.count);
360 for (NSString *storageName in allStorages) {
363 NSLog(
@"Storage '%@' contains %lu items", storageName, (
unsigned long)keys.count);
373 for (NSString *key in keys) {
375 NSString *stringValue = [
storage getString:key defaultValue:@""];
376 if (stringValue.length > 0) {
381 int32_t intValue = [
storage getInt:key defaultValue:-999999];
382 if (intValue != -999999) {
387 int64_t longValue = [
storage getLong:key defaultValue:-999999];
388 if (longValue != -999999) {
393 BOOL boolValue = [
storage getBool:key defaultValue:NO];
394 if ([storage contains:key]) {
399 float floatValue = [
storage getFloat:key defaultValue:-999999.0f];
400 if (floatValue != -999999.0f) {
405 double doubleValue = [
storage getDouble:key defaultValue:-999999.0];
406 if (doubleValue != -999999.0) {
411 NSLog(
@" - Strings: %d", stringCount);
412 NSLog(
@" - Integers: %d", intCount);
413 NSLog(
@" - Longs: %d", longCount);
414 NSLog(
@" - Booleans: %d", boolCount);
415 NSLog(
@" - Floats: %d", floatCount);
416 NSLog(
@" - Doubles: %d", doubleCount);
424 if (
self.storageManager == nil) {
425 NSLog(
@"StorageManager not initialized");
429 NSLog(
@"\n=== Data Migration Demonstration ===");
436 [
oldStorage putString:@"name" value:@"John Doe"];
441 NSLog(
@"Old storage before migration:");
442 [
self demonstrateStorageData:oldStorage];
446 for (NSString *key in keys) {
448 NSString *stringValue = [
oldStorage getString:key defaultValue:@""];
449 if (stringValue.length > 0) {
455 int32_t intValue = [
oldStorage getInt:key defaultValue:-999999];
456 if (intValue != -999999) {
462 int64_t longValue = [
oldStorage getLong:key defaultValue:-999999];
463 if (longValue != -999999) {
469 BOOL boolValue = [
oldStorage getBool:key defaultValue:NO];
470 if ([oldStorage contains:key]) {
476 float floatValue = [
oldStorage getFloat:key defaultValue:-999999.0f];
477 if (floatValue != -999999.0f) {
483 double doubleValue = [
oldStorage getDouble:key defaultValue:-999999.0];
484 if (doubleValue != -999999.0) {
489 NSLog(
@"\nNew storage after migration:");
490 [
self demonstrateStorageData:newStorage];
494 NSLog(
@"\nRemoved old storage");
498 NSLog(
@"Final storage list: %@", finalStorages);
505 if (
self.storageManager == nil) {
506 NSLog(
@"StorageManager not initialized");
510 NSLog(
@"\n=== Storage Cleanup Demonstration ===");
518 NSLog(
@"Storages before cleanup: %@", beforeCleanup);
522 for (NSString *storageName in storages) {
523 if ([storageName hasPrefix:
@"temp_"]) {
525 NSLog(
@"Removed temporary storage: %@", storageName);
530 NSLog(
@"Storages after cleanup: %@", afterCleanup);