如何在判断一个类是否在当前SDK版本中是否存在?

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
    Class JSONSerialization = NSClassFromString(@"NSJSONSerialization");
    
    if (JSONSerialization) {
        NSLog(@"NSJSONSerialization exist!");
    }
    else
    {
        NSLog(@"NSJSONSerialization not exist!");
    }
    
    JSONSerialization = NSClassFromString(@"JSONSerialization");
    
    if (JSONSerialization) {
        NSLog(@"JSONSerialization exist!");
    }
    else
    {
        NSLog(@"JSONSerialization not exist!");
    }