Previous | Index | Next |
List manipulation methods
subarraysFrom:usingKeys:outKeys:error:
Pass a list of records/dictionaries and a list of labels, and a list of lists will be returned, with the order of the values in each sublist matching the order of the labels. If an empty list is passed for usingKeys, the keys of the first item will be used, sorted in case-insensitive alphabetical order, and these keys will be listed as strings in outKeys.
+ (NSArray *)subarraysFrom:(NSArray *)arrayOfDicts usingKeys:(NSArray *)theKeys outKeys:(NSArray *__autoreleasing *)outKeys error:(NSError *__autoreleasing *)outError
arrayOfDicts = array of dictionaries/records
theKeys = list of record keys as strings
outKeys = missing value or reference
outError = missing value or reference
An array of sublists. If outKeys is reference, also an array of the keys found, in order.
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 arrayOfDicts to {{firstLabel:1.1, secondLabel:2}, {firstLabel:3, secondLabel:4}, {firstLabel:5, secondLabel:6}}
set theKeys to {"firstLabel", "secondLabel"}
set theResult to current application's SMSForder's subarraysFrom:arrayOfDicts usingKeys:theKeys outKeys:(missing value) |error|:(missing value)
ASify from theResult
--> {{1.1, 2}, {3, 4}, {5, 6}}
theResult as list -- 10.11 only
--> {{1.1, 2}, {3, 4}, {5, 6}}
theResult as list -- 10.9 and 10.10
--> {{1.100000023842, 2}, {3, 4}, {5, 6}}
set theKeys to {}
set {theResult, keysUsed} to current application's SMSForder's subarraysFrom:arrayOfDicts usingKeys:theKeys outKeys:(reference) |error|:(missing value)
ASify from theResult
--> {{1.1, 2}, {3, 4}, {5, 6}}
theResult as list -- 10.11 only
--> {{1.1, 2}, {3, 4}, {5, 6}}
theResult as list -- 10.9 and 10.10
--> {{1.100000023842, 2}, {3, 4}, {5, 6}}
ASify from keysUsed
--> {"firstLabel", "secondLabel"}