isKindOfClass nie działa zgodnie z oczekiwaniami
Pracuję nad projektem iOS5 + (xcode 4.4.1 SDK 5.1)
Mam ten kod w teście jednostkowym:
[_appDelegate application:nil didFinishLaunchingWithOptions:nil];
UITabBarController *tabBarController = (UITabBarController*)_appDelegate.window.rootViewController;
NSArray *viewControllers = [tabBarController viewControllers];
UINavigationController *nc_1 = [viewControllers objectAtIndex:0];
UIViewController *vc_1 = nc_1.topViewController;
STAssertTrue([vc_1 isKindOfClass:[ScheduleViewController class]]==YES, @"UITabBarController first tab should be a ScheduleViewController class");
Jeśli uruchomię test, test nie powiedzie się.
Sprawdzam więc z debuggerem:
(lldb) po [ScheduleViewController class]
(id) $1 = 0x00142b04 ScheduleViewController
(lldb) po vc_1
(UIViewController *) $2 = 0x11a32dc0 <ScheduleViewController: 0x11a32dc0>
(lldb) print (BOOL) [vc_1 isKindOfClass:(Class)[ScheduleViewController class]]
(BOOL) $4 = YES
(lldb) po [vc_1 class]
(id) $5 = 0x00142b04 ScheduleViewController
(lldb)
W aplikacji: didFinishLaunchingWithOptions: tworzę ScheduleViewController i używam go jako rootController kontrolera nawigacji. Debugger mówi, że jest poprawny. Nie rozumiem, co jest nie tak z powyższym stwierdzeniem.
Ktoś ma o tym pomysł?
Aktualizacja
Pierwszym wdrożeniem było:
STAssertTrue([vc_1 isKindOfClass:[ScheduleViewController class]], @"UITabBarController first tab should be a ScheduleViewController class");
Twierdzenie nie powiodło się w ten sam sposób.
Aktualizacja 2
Jak zasugerowano w komentarzu, staram się dodać ten fragment kodu przed asercją:
BOOL vcBool = [vc_1 isKindOfClass:[ScheduleViewController class]];
Z debuggerem widzę:
(lldb) print (BOOL) [vc_1 isKindOfClass:(Class)[ScheduleViewController class]]
(BOOL) $1 = YES
(lldb) print (BOOL) vcBool
(BOOL) $2 = NO
(lldb)
Aktualizacja 3
Dodałem tę linię, jak zasugerowałem w komentarzach, przed stwierdzeniem:
NSLog(@"vc_1=%@ class=%@", vc_1, NSStringFromClass([vc_1 class]));
Z konsoli debugowania:
vc_1=<ScheduleViewController: 0x993bdb0> class=ScheduleViewController