Last active
November 29, 2015 08:36
-
-
Save romashamin/82d720e2210b3839d24e to your computer and use it in GitHub Desktop.
Code snippet to check if `sortLayers` function works properly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. Open Sketch.app and select a number of artboards | |
// 2. Open Plugins → Custom Plugin... (Ctrl+Shift+K) | |
// 3. Paste the snippet there and Run | |
// In the field below you can see the properly sorted list of selected artboards | |
var doc = context.document | |
var selection = context.selection | |
function sortLayers(layers, isAscending) { | |
var sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:'name' | |
ascending:isAscending | |
selector:'localizedStandardCompare:'] | |
return [layers sortedArrayUsingDescriptors:[sortDescriptor]] | |
} | |
function getNames(layers) { | |
var names = [] | |
var loop = layers.objectEnumerator() | |
while (item = loop.nextObject()) { | |
var itemName = [item name] | |
names.push(itemName) | |
} | |
return names | |
} | |
log(getNames(sortLayers(selection, true))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment