I want to include code in my plugin that checks what version of Sketch is running so I can handle different API versions.
NSBundle.mainBundle().infoDictionary()["CFBundleShortVersionString"]
This will return something like 51.3
51.3
It might be better to check for the existence of methods/properties.
markh What would the code look like for checking for the existence of a method? For example:
MSAvailableOverride.isAffectedLayerOrParentHidden()
You could do the following:
MSAvailableOverride.instancesRespondToSelector(NSSelectorFromString("isAffectedLayerOrParentHidden"))
markh Thanks. Works perfectly!
Now I need to figure out how to cope without this method, which seems to have gone missing in Sketch 52.
https://sketchplugins.com/d/1011-sketch-52-alternative-to-override-isaffectedlayerorparentlocked
Alternatively, you can do this:
const sketch = require('sketch') console.log(sketch.version.sketch) // Sketch version, currently 52 console.log(sketch.version.api) // API version, currently 2.0.0
Hope it helps!