Просмотр исходного кода

Made references to Realm build optional.

Tim Oliver лет назад: 10
Родитель
Сommit
b6453ac360

+ 1 - 2
Classes/GlobalStateExplorers/DatabaseBrowser/FLEXDatabaseManager.h

@@ -15,8 +15,7 @@
 
 @protocol FLEXDatabaseManager <NSObject>
 
-@property (nonatomic, readonly) NSString *path;
-
+@optional
 - (instancetype)initWithPath:(NSString*)path;
 
 - (BOOL)open;

+ 36 - 5
Classes/GlobalStateExplorers/DatabaseBrowser/FLEXRealmDatabaseManager.m

@@ -8,9 +8,10 @@
 
 #import "FLEXRealmDatabaseManager.h"
 
-//#if __has_include("<Realm/Realm.h>")
+#if __has_include("<Realm/Realm.h>")
 
 #import <Realm/Realm.h>
+#import <Realm/RLMRealm_Dynamic.h>
 
 @interface FLEXRealmDatabaseManager ()
 
@@ -19,8 +20,12 @@
 
 @end
 
+#endif
+
 @implementation FLEXRealmDatabaseManager
 
+#if __has_include("<Realm/Realm.h>")
+
 - (instancetype)initWithPath:(NSString*)aPath
 {
     self = [super init];
@@ -62,14 +67,40 @@
 
 - (NSArray *)queryAllColumnsWithTableName:(NSString *)tableName
 {
-    return nil;
+    RLMObjectSchema *objectSchema = [self.realm.schema schemaForClassName:tableName];
+    if (objectSchema == nil) {
+        return nil;
+    }
+    
+    NSMutableArray *columnNames = [NSMutableArray array];
+    for (RLMProperty *property in objectSchema.properties) {
+        [columnNames addObject:property.name];
+    }
+    
+    return columnNames;
 }
 
 - (NSArray *)queryAllDataWithTableName:(NSString *)tableName
 {
-    return nil;
+    RLMObjectSchema *objectSchema = [self.realm.schema schemaForClassName:tableName];
+    RLMResults *results = [self.realm allObjects:tableName];
+    if (results.count == 0 || objectSchema == nil) {
+        return nil;
+    }
+    
+    NSMutableArray *allDataEntries = [NSMutableArray array];
+    for (RLMObject *result in results) {
+        NSMutableDictionary *entry = [NSMutableDictionary dictionary];
+        for (RLMProperty *property in objectSchema.properties) {
+            entry[property.name] = [result valueForKey:property.name];
+        }
+        
+        [allDataEntries addObject:entry];
+    }
+    
+    return allDataEntries;
 }
 
-@end
+#endif
 
-//#endif
+@end

+ 7 - 1
Classes/GlobalStateExplorers/DatabaseBrowser/FLEXTableListViewController.m

@@ -7,9 +7,12 @@
 //
 
 #import "FLEXTableListViewController.h"
+
 #import "FLEXDatabaseManager.h"
 #import "FLEXSQLiteDatabaseManager.h"
+#if __has_include("<Realm/Realm.h>")
 #import "FLEXRealmDatabaseManager.h"
+#endif
 
 #import "FLEXTableContentViewController.h"
 
@@ -45,9 +48,12 @@
     if ([@[@"db", @"sqlite", @"sqlite3"] indexOfObject:pathExtension] != NSNotFound) {
         return [[FLEXSQLiteDatabaseManager alloc] initWithPath:path];
     }
-    else if ([pathExtension isEqualToString:@"realm"]) {
+    
+#if __has_include("<Realm/Realm.h>")
+    if ([pathExtension isEqualToString:@"realm"]) {
         return [[FLEXRealmDatabaseManager alloc] initWithPath:path];
     }
+#endif
     
     return nil;
 }

+ 6 - 1
Classes/GlobalStateExplorers/FLEXFileBrowserTableViewController.m

@@ -217,9 +217,14 @@
                 drillInViewController = [[FLEXWebViewController alloc] initWithText:prettyString];
             } else if ([FLEXWebViewController supportsPathExtension:pathExtension]) {
                 drillInViewController = [[FLEXWebViewController alloc] initWithURL:[NSURL fileURLWithPath:fullPath]];
-            } else if ([@[@"db", @"sqlite3", @"realm"] containsObject:[subpath pathExtension]]) {
+            } else if ([@[@"db", @"sqlite", @"sqlite3"] containsObject:[subpath pathExtension]]) {
               drillInViewController = [[FLEXTableListViewController alloc] initWithPath:fullPath];
             }
+#if __has_include("<Realm/Realm.h>")
+            else if ([@[@"realm"] containsObject:[subpath pathExtension]]) {
+                drillInViewController = [[FLEXTableListViewController alloc] initWithPath:fullPath];
+            }
+#endif
             else {
                 NSString *fileString = [NSString stringWithContentsOfFile:fullPath encoding:NSUTF8StringEncoding error:NULL];
                 if ([fileString length] > 0) {