Previous | Index | Next |
List manipulation methods
arrayByInsertingItems:inArray:atIndex:error:
Inserts a list of items as separate items into the list. Index is zero-based.
+ (NSArray *)arrayByInsertingItems:(id)listOrArrayToInsert inArray:(NSArray *)listOrArray atIndex:(NSInteger)atIndex error:(NSError *__autoreleasing *)outError
listOrArrayToInsert = list or array of items to insert
listOrArray = target list or array
atIndex = zero-based index to insert at
outError = missing value or reference
An array
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 {1.1, 2, 3, 4, 5, 6}
set insertList to {"x", "y", "z"}
set theResult to current application's SMSForder's arrayByInsertingItems:insertList inArray:listOrArray atIndex:0 |error|:(missing value)
ASify from theResult
--> {"x", "y", "z", 1.1, 2, 3, 4, 5, 6}
theResult as list -- 10.11 only
--> {"x", "y", "z", 1.1, 2, 3, 4, 5, 6}
theResult as list -- 10.9 and 10.10
--> {"x", "y", "z", 1.100000023842, 2, 3, 4, 5, 6}
set theResult to current application's SMSForder's arrayByInsertingItems:insertList inArray:listOrArray atIndex:3 |error|:(missing value)
ASify from theResult
--> {1.1, 2, 3, "x", "y", "z", 4, 5, 6}
theResult as list -- 10.11 only
--> {1.1, 2, 3, "x", "y", "z", 4, 5, 6}
theResult as list -- 10.9 and 10.10
--> {1.100000023842, 2, 3, "x", "y", "z", 4, 5, 6}
set {theResult, theError} to current application's SMSForder's arrayByInsertingItems:insertList inArray:listOrArray atIndex:7 |error|:(reference)
if theResult = missing value then error (theError's localizedDescription() as text)
--> error number -2700 Index is out of range.