Previous Index Next

BridgePlus.framework, SMSForder Class Methods

Category

List manipulation methods

Method

subarraysIn:sortedByIndexes:ascending:sortTypes:sortKeys:error:

Summary

As in subarraysIn:sortedByIndexes:ascending:sortTypes:error:, but you can also pass a list of key strings to be used for the sort. Pass an empty list to use "self" throughout, which is what the above method uses. For example, if you pass {"length"}, the sorting will be done on the basis of the length. The values being sorted must support the key or an error will be thrown.

Signature

+ (NSArray *)subarraysIn:(NSArray *)listOrArray sortedByIndexes:(NSArray *)theIndexes ascending:(NSArray *)orderBooleans sortTypes:(NSArray *)sortSelctorStrings sortKeys:(NSArray *)sortKeys error:(NSError *__autoreleasing *)outError

Parameters

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

sortKeys = a list of the sort keys to use. Can be empty; see summary

outError = missing value or reference

Result

Sorted array of sublists

Availability

Version 1.0.0

Notes

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.

Sample

use scripting additions

use framework "Foundation"

use script "BridgePlus"

load framework


set listOrArray to {{5, 2.1, 7}, {1, 2.2, 3}, {4, 2.3, 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 sortKeys:{"integerValue"} |error|:(missing value)

ASify from theResult

--> {{10, 1, 12}, {1, 2.2, 3}, {4, 2.3, 6}, {5, 2.1, 7}, {7, 3, 9}}

theResult as list -- 10.11 only

--> {{10, 1, 12}, {1, 2.2, 3}, {4, 2.3, 6}, {5, 2.1, 7}, {7, 3, 9}}

theResult as list -- 10.9 and 10.10

--> {{10, 1, 12}, {1, 2.200000047684, 3}, {4, 2.299999952316, 6}, {5, 2.099999904633, 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 sortKeys:{} |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.


Click here to open script in a script editor