Previous Index Next

BridgePlus.framework, SMSForder Class Methods

Category

List manipulation methods

Method

splitArray:byKey:sortKeys:

Summary

Pass an array of items, and have them split into subarrays according to the provided key. The optional sortKeys are used to sort the objects within the subarrays; pass an empty list if you do not need them sorted. Items not responding to the key are grouped last.

Signature

+ (NSArray *)splitArray:(NSArray *)listOrArray byKey:(NSString *)splitKey sortKeys:(NSArray *)sortKeys

Parameters

listOrArray = list or array to split

splitKey = the key to use as the basis for the split

sortKeys = the keys to sort each sublist on

Result

A sorted array of sublists

Availability

Version 1.3.0

Notes

 

Sample

use scripting additions

use framework "Foundation"

use script "BridgePlus"

load framework


set listOrArray to {"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"}

set theResult to current application's SMSForder's splitArray:listOrArray byKey:"length" sortKeys:{"self"}

ASify from theResult

--> {{"one", "six", "ten", "two"}, {"five", "four", "nine"}, {"eight", "seven", "three"}}

theResult as list

--> {{"one", "six", "ten", "two"}, {"five", "four", "nine"}, {"eight", "seven", "three"}}


set listOrArray to current application's SMSForder's resourceValuesForKeys:{current application's NSURLTypeIdentifierKey, current application's NSURLNameKey} forFilesIn:(path to desktop) recursive:true

set theResult to current application's SMSForder's splitArray:listOrArray byKey:(current application's NSURLTypeIdentifierKey) sortKeys:{current application's NSURLNameKey}

set finalList to {}

repeat with anArray in theResult

set end of finalList to ASify from (anArray's valueForKey:(current application's NSURLPathKey))

end repeat

return finalList

--> list of sublists of POSIX paths, one sublist for each identifier

return


Click here to open script in a script editor