Previous Index Next

BridgePlus.framework, SMSForder Class Methods

Category

List manipulation methods

Method

subarraysIn:asDictionariesUsingLabels:error:

Summary

Assumes the array is a list of lists, and that each list has the same number of items as the list of labels. The result will be an array of records/dictionaries that use the supplied labels in order.

Signature

+ (NSArray *)subarraysIn:(NSArray *)listOrArray asDictionariesUsingLabels:(NSArray *)theLabels error:(NSError *__autoreleasing *)outError

Parameters

listOrArray = list or array of sublists

theLabels = list of labels to use for values

outError = missing value or reference

Result

An array of dictionaries/records

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 {{1.1, 2}, {3, 4}, {5, 6}}

set theLabels to {"firstLabel", "secondLabel"}

set theResult to current application's SMSForder's subarraysIn:listOrArray asDictionariesUsingLabels:theLabels |error|:(missing value)

ASify from theResult

--> {{firstLabel:1.1, secondLabel:2}, {firstLabel:3, secondLabel:4}, {firstLabel:5, secondLabel:6}}

theResult as list -- 10.11 only

--> {{firstLabel:1.1, secondLabel:2}, {firstLabel:3, secondLabel:4}, {firstLabel:5, secondLabel:6}}

theResult as list -- 10.9 and 10.10

--> {{firstLabel:1.100000023842, secondLabel:2}, {firstLabel:3, secondLabel:4}, {firstLabel:5, secondLabel:6}}


set theLabels to {"firstLabel", "secondLabel", "thirdLabel"}

set {theResult, theError} to current application's SMSForder's subarraysIn:listOrArray asDictionariesUsingLabels:theLabels |error|:(reference)

if theResult = missing value then error (theError's localizedDescription() as text)

--> error number -2700  Lists and label lists differ in length.


Click here to open script in a script editor