isKindOfClass doesn't work as expected

前端 未结 3 1287
逝去的感伤
逝去的感伤 2021-02-06 02:11

i\'m working on a iOS5+ project (xcode 4.4.1 SDK 5.1)

i have this code inside a unit test:

[_appDelegate application:nil didFinishLaunchingWithOptions:ni         


        
相关标签:
3条回答
  • 2021-02-06 02:30

    I found the solution.

    It's the inverse of the solution presented in the post linked by @vacawama in the comments. I had all *.m source of the app target in the test target too. While i was searching for a solution to the isKindOfClass problem i noticed a lot of warning on the console at the begin of the test session. The warnings was like this:

    Class AClass is implemented in both /Application Support/iPhone Simulator/5.0/Applications/7FC68A9C-4F2C-4A30-85AD-87D8ABA7A275/App.app/App and /Developer/Xcode/DerivedData/App-fvbgaqbdupuoodgquxhlwbudpsin/Build/Products/Debug-iphonesimulator/App.octest/AppTests. One of the two will be used. Which one is undefined.
    

    I removed all .m files of the application from test target.

    Now isKindOfClass works as expected.

    Thank to all for the support.

    0 讨论(0)
  • 2021-02-06 02:30

    You shouldn't directly compare BOOL values to YES. It's possible this is causing the issue with your assert. Here's a reference with background on the issue: http://mobiledevelopertips.com/objective-c/of-bool-and-yes.html

    0 讨论(0)
  • 2021-02-06 02:51

    Converting a class name to string with NSStringFromClass will avoid problems with isKindOfClass... example:

    if ([NSStringFromClass([AViewController class]) isEqualToString:NSStringFromClass([BViewController class])])
    
    0 讨论(0)
提交回复
热议问题