1

I'm having big troubles with NSClassFromString in swift when running iOS7.

In a swift file called Common.swift I have the following variable:

let IS_IOS8: Bool = NSClassFromString("UIAlertController") != nil

which I use in my app to test wheter it's running in iOS8 or not.

The problem is that it causes a crash on iOS7, but only on real devices and not on the simulator. Since I do not have any actual device, I tested my app only using the simulator and now my users are reporting crashing with such iOS version.

The crash report says:

Thread 0 Crashed:
0   libsystem_kernel.dylib             0x39a116d8 0x399ff000 + 75480
1   AppName                           CLSSignalHandler (in AppName) + 188
2   libsystem_platform.dylib           0x39a75720 0x39a72000 + 14112
3   AppName                           globalinit_func0 (in AppName) (Common.swift:10)
4   AppName                           globalinit_func0 (in AppName) (Common.swift:10)
5   libswiftCore.dylib                 0x005f77c4 0x464000 + 1652676
6   libdispatch.dylib                  0x39946d3c 0x39946000 + 3388
7   libdispatch.dylib                  0x3994796a 0x39946000 + 6506
8   libswiftCore.dylib                 0x005f77ae 0x464000 + 1652654
9   AppName                           AppName.mutableAddressor : Swift.Bool (in AppName) (Common.swift:0)
10  AppName                           AppName.BSMessageBarView.init (AppName.BSMessageBarView.Type)(frame : C.CGRect, style : AppName.BSMessageBarViewStyle) -> AppName.BSMessageBarView (in AppName) (BSMessageBarView.swift:36)
11  AppName                           AppName.BSMessageBarView.__allocating_init (AppName.BSMessageBarView.Type)(frame : C.CGRect, style : AppName.BSMessageBarViewStyle) -> AppName.BSMessageBarView (in AppName) (BSMessageBarView.swift:0)
12  AppName                           AppName.BSNavigationController.viewDidLoad (AppName.BSNavigationController)() -> () (in AppName) (BSNavigationController.swift:25)
13  UIKit                              0x314faa4e 0x314eb000 + 64078
14  UIKit                              0x314fa80c 0x314eb000 + 63500
15  UIKit                              0x31501484 0x314eb000 + 91268
16  UIKit                              0x314fedd4 0x314eb000 + 81364
17  UIKit                              0x31568a4c 0x314eb000 + 514636
18  UIKit                              0x315656e0 0x314eb000 + 501472
19  UIKit                              0x3155fcc4 0x314eb000 + 478404
20  UIKit                              0x314fbc92 0x314eb000 + 68754
21  UIKit                              0x314fadf4 0x314eb000 + 65012
22  UIKit                              0x3155f400 0x314eb000 + 476160
23  GraphicsServices                   0x33b68b52 0x33b5e000 + 43858
24  GraphicsServices                   0x33b6873a 0x33b5e000 + 42810
25  CoreFoundation                     0x2ec91844 0x2ebf2000 + 653380
26  CoreFoundation                     0x2ec917de 0x2ebf2000 + 653278
27  CoreFoundation                     0x2ec8ffaa 0x2ebf2000 + 647082
28  CoreFoundation                     0x2ebfa764 0x2ebf2000 + 34660
29  CoreFoundation                     0x2ebfa546 0x2ebf2000 + 34118
30  UIKit                              0x3155e626 0x314eb000 + 472614
31  UIKit                              0x3155988c 0x314eb000 + 452748
32  AppName                           main (in AppName) (AppDelegate.swift:0)
33  libdyld.dylib                      0x3995bab4 0x3995a000 + 6836

where BSMessageBarView is a subclass of UIView and BSNavigationController is a subclass of UINavigationController. Morover, in BSMessageBarView.swift:36 (line 10 of the crash report) I am testing whether IS_IOS8 is true or false:

if IS_IOS8 {
  ...
} else {
  ...
}

I do not have any idea about why this is happening.

Thanks for any help.

Andrea

a.periz
  • 565
  • 1
  • 6
  • 18

0 Answers0