Previous | Index | Next |
List manipulation methods
subarraysIn:sortedByIndexes:ascending:sortTypes:error:
Sort a lists of lists based on indexes of the sublists. So if the (zero-based) indexes are {3, 2}, the list will be sorted based on the value of the fourth item of the sublists, and in cases of equality, then on the third. The ascending argument should be a list of booleans, matching the indexes; if it has fewer entries, the last entry will be used for subsequent sort order. Pass an empty list to use true throughout. The sortTypes argument should be a list of strings consisting of the comparison selectors to use: "compare:", "localizedCompare:", "caseInsensitiveCompare:", "localizedCaseInsensitiveCompare:" and "localizedStandardCompare:". Pass an empty list to use "compare:" throughout.
+ (NSArray *)subarraysIn:(NSArray *)listOrArray sortedByIndexes:(NSArray *)theIndexes ascending:(NSArray *)orderBooleans sortTypes:(NSArray *)sortSelctorStrings error:(NSError *__autoreleasing *)outError
listOrArray = list or array of sublists
theIndexes = a list of the zero-based indexes of the sublist items to sort on, in order
orderBooleans = a list of booleans setting the sort order. Can be empty; see summary
sortSelctorStrings = a list of the sort selectors to use Can be empty; see summary
outError = missing value or reference
Sorted array of sublists
Version 1.0.0
If you set outError to reference, the result will be a list of two items. If there is no error, the first item will be the result of the method and the second will be missing value. If there is an error, the first item will be missing value and the second item with be an NSError.
use scripting additions
use framework "Foundation"
use script "BridgePlus"
load framework
set listOrArray to {{5, 2, 7}, {1.1, 2, 3}, {4, 2, 6}, {7, 3, 9}, {10, 1, 12}}
set theIndexes to {1, 0}
set theOrders to {true, true}
set sortTypes to {"compare:", "compare:"}
set theResult to current application's SMSForder's subarraysIn:listOrArray sortedByIndexes:theIndexes ascending:theOrders sortTypes:sortTypes |error|:(missing value)
ASify from theResult
--> {{10, 1, 12}, {1.1, 2, 3}, {4, 2, 6}, {5, 2, 7}, {7, 3, 9}}
theResult as list -- 10.11 only
--> {{10, 1, 12}, {1.1, 2, 3}, {4, 2, 6}, {5, 2, 7}, {7, 3, 9}}
theResult as list -- 10.9 and 10.10
--> {{10, 1, 12}, {1.100000023842, 2, 3}, {4, 2, 6}, {5, 2, 7}, {7, 3, 9}}
set theIndexes to {1, 3}
set {theResult, theError} to current application's SMSForder's subarraysIn:listOrArray sortedByIndexes:theIndexes ascending:theOrders sortTypes:sortTypes |error|:(reference)
if theResult = missing value then error (theError's localizedDescription() as text)
--> error number -2700 Sublist has fewer items than in sort indexes list.