How to know what Mac OS the app is running on?

后端 未结 7 1996
遥遥无期
遥遥无期 2020-12-31 18:30

I\'ve seen in some projects something like:

#if .....
    code...
#endif

but i can\'t find it now...
Let\'s say, for example, if the ap

7条回答
  •  既然无缘
    2020-12-31 18:47

    As Steven Fisher said, you should not check for the system version but for the availability of the class or method you want to use.

    The check if a specific class is available use

    if ([NSHologram class]) {
       // Create an instance of the class and use it.
    } else {
       // The Hologram class is not available.
    }
    

    To check if a specific method is available use

    NSString* hologramText = @"Hologram";
    if ([hologramText respondsToSelector:@selector(convertHologram)]) {
        [hologramText convertHologram];
    }
    

    Yet for the method checking, the method must be available on the system where you build your app, or else you will get a compile error.

提交回复
热议问题