Kaynağa Gözat

Separated register global entry API to object and viewcontroller parts.

Mikhail Solodovnichenko 11 yıl önce
ebeveyn
işleme
a644f89bbd

+ 9 - 9
Classes/Explorer Toolbar/FLEXManager.h

@@ -23,18 +23,18 @@
 /// @param entryName The string to be displayed in the cell.
 /// @param objectFutureBlock When you tap on the row, information about the object returned by this block will be displayed.
 /// Passing a block that returns an object allows you to display information about an object whose actual pointer may change at runtime (e.g. +currentUser)
-/// @param forceObjectExplorer Specifies how to interpret object returned from objectFutureBlock. If YES it will create object/class inspector view controller
-/// for any supplied object, while NO will cause any passed UIViewController subclasses to be pushed into manager's navigation view controller.
 /// @note This method must be called from the main thread.
 /// The objectFutureBlock will be invoked from the main thread and may return nil.
 /// @note The passed block will be copied and retain for the duration of the application, you may want to use __weak references.
-- (void)registerGlobalEntryWithName:(NSString *)entryName
-                  objectFutureBlock:(id (^)(void))objectFutureBlock
-                forceObjectExplorer:(BOOL)forceObjectExplorer;
+- (void)registerGlobalEntryWithName:(NSString *)entryName objectFutureBlock:(id (^)(void))objectFutureBlock;
 
-/**
- *  The same as -registerGlobalEntryWithName:objectFutureBlock:forceObjectExplorer: passing YES for forceObjectExplorer.
- */
-- (void)registerGlobalEntryWithName:(NSString *)entryName objectFutureBlock:(id(^)(void))objectFutureBlock;
+/// Adds an entry at the bottom of the list of Global State items. Call this method before this view controller is displayed.
+/// @param entryName The string to be displayed in the cell.
+/// @param viewControllerFutureBlock When you tap on the row, view controller returned by this block will be pushed on the navigation controller stack.
+/// @note This method must be called from the main thread.
+/// The viewControllerFutureBlock will be invoked from the main thread and may not return nil.
+/// @note The passed block will be copied and retain for the duration of the application, you may want to use __weak references.
+- (void)registerGlobalEntryWithName:(NSString *)entryName
+          viewControllerFutureBlock:(UIViewController * (^)(void))viewControllerFutureBlock;
 
 @end

+ 17 - 15
Classes/Explorer Toolbar/FLEXManager.m

@@ -104,31 +104,33 @@
 
 - (void)registerGlobalEntryWithName:(NSString *)entryName objectFutureBlock:(id (^)(void))objectFutureBlock
 {
-    [self registerGlobalEntryWithName:entryName objectFutureBlock:objectFutureBlock forceObjectExplorer:YES];
+    NSParameterAssert(entryName);
+    NSParameterAssert(objectFutureBlock);
+    NSAssert([NSThread isMainThread], @"This method must be called from the main thread.");
+
+    entryName = entryName.copy;
+    FLEXGlobalsTableViewControllerEntry *entry = [FLEXGlobalsTableViewControllerEntry entryWithNameFuture:^NSString *{
+        return entryName;
+    } viewControllerFuture:^UIViewController *{
+        return [FLEXObjectExplorerFactory explorerViewControllerForObject:objectFutureBlock()];
+    }];
+
+    [self.userGlobalEntries addObject:entry];
 }
 
-- (void)registerGlobalEntryWithName:(NSString *)entryName
-                  objectFutureBlock:(id (^)(void))objectFutureBlock
-                forceObjectExplorer:(BOOL)forceObjectExplorer
+- (void)registerGlobalEntryWithName:(NSString *)entryName viewControllerFutureBlock:(UIViewController * (^)(void))viewControllerFutureBlock
 {
     NSParameterAssert(entryName);
-    NSParameterAssert(objectFutureBlock);
+    NSParameterAssert(viewControllerFutureBlock);
     NSAssert([NSThread isMainThread], @"This method must be called from the main thread.");
 
     entryName = entryName.copy;
     FLEXGlobalsTableViewControllerEntry *entry = [FLEXGlobalsTableViewControllerEntry entryWithNameFuture:^NSString *{
         return entryName;
     } viewControllerFuture:^UIViewController *{
-        id object = objectFutureBlock();
-
-        if([object_getClass(object) isSubclassOfClass:[UIViewController class]] && forceObjectExplorer == NO)
-        {
-            return object;
-        }
-        else
-        {
-            return [FLEXObjectExplorerFactory explorerViewControllerForObject:object];
-        }
+        UIViewController *viewController = viewControllerFutureBlock();
+        NSCAssert(viewController, @"'%@' entry returned nil viewController. viewControllerFutureBlock should never return nil.", entryName);
+        return viewControllerFutureBlock();
     }];
 
     [self.userGlobalEntries addObject:entry];

+ 4 - 5
Example/UICatalog/AAPLCatalogTableTableViewController.m

@@ -63,12 +63,11 @@
 
 
 
-    // return it in objectFutureBlock
+    // return it in viewControllerFutureBlock
     [[FLEXManager sharedManager] registerGlobalEntryWithName:@"Custom superpowers"
-                                           objectFutureBlock:^id{
-                                               return viewController;
-                                           }
-                                         forceObjectExplorer:NO];
+                                   viewControllerFutureBlock:^id{
+                                       return viewController;
+                                   }];
 }
 
 @end